3 ms·
As a rule of thumb, when ever one thinks that "wow, this code I just wrote is really clever", it should be a sign to sit back, take another approach and rewrite
by juhq 12y ago
As a rule of thumb, when ever one thinks that "wow, this code I just wrote is really clever", it should be a sign to sit back, take another approach and rewrite that code.
Clever code almost always means that in hindsight it's terrible and will introduce bugs.
In my opinion "x.indexOf(y) !== 0" is a lot more clearer and will immediately tells other developers what is happening. No point in saving space code, that's why we have minification libraries.
- lstamour 12y agoNobody needs this correction, I hope, but to be clear, it's !== -1 that we're replacing with ~. Then again, maybe this stands as a valid reason to be explicit in the first place. ;-)