zertosh / invariant

invariant
MIT License
1.22k stars 70 forks source link

Use spread operator to get the arguments more safely #33

Open cyan33 opened 6 years ago

cyan33 commented 6 years ago

Hi @zertosh,

Don't know if this repo is still under maintainence. Anyway, I've noticed that it uses a, b, c, d, e as placeholders for the %s to be replaced. This could be easily improved by using the spread operator. It enhances the readability and is more safe in case the length of the placeholders is more than 5.

Would love to listen to your thought on this. 😄

adamdicarlo commented 6 years ago

I'd be concerned that the spread operator in the function signature would result in the argument spreading being executed on every call, not just failing ones. How about old-school use of arguments when the condition fails?

Sceat commented 4 years ago

@adamdicarlo i don't see how is that a problem

adamdicarlo commented 4 years ago

@Sceat Yeah, me neither, now (that was a while ago). At the time I was thinking it could be a performance issue. With eliminating these kinds of checks in production builds, it's no issue at all (maybe that wasn't standard when I commented? :thinking: ) ... even for debug builds I don't think it's nearly inefficient enough to be a problem.