4 ms·
I can't speak for Brendan, but I generally think && / || are great for assignment, but otherwise it's code-smell. var foo = obj && obj.bar; // great !i
by jayferd 14y ago
I can't speak for Brendan, but I generally think && / || are great for assignment, but otherwise it's code-smell.
var foo = obj && obj.bar; // great
!isActive && $parent.toggleClass('open'); // smelly
if (!isActive) $parent.toggleClass('open'); // better
- RegEx 14y agoI believe HTML5 boilerplate implements the smelly pattern. https://github.com/h5bp/html5-boilerplate/blob/master/index.html#L44 https://github.com/h5bp/html5-boilerplate/blob/master/index....
- astrec 14y agoif (!isActive) { $parent.toggleClass('open'); } // best Damian Conway of Perl fame wrote an excellent style guide for C in the early/mid 90s which I'm pretty sure explained why (I can't find my copy): Programmer A: if (!isActive) $parent.toggleClass('open'); Programmer B: if (!isActive) $parent.toggleClass('open'); doSomethingElse(); Oh dear.
- jayferd 14y agoYep, that's why I always demand that if you're not going to use curlies, you make it a one-liner. // okay if (!isActive) $parent.toggleClass('open'); // not okay if (!isActive) $parent.toggleClass('open'); That way you know when you change it to two lines, you have to add curlies.