Live data from Hacker News

Brendan Eich: The infernal semicolon

brendaneich.com

141–143 of 143 posts

Re: Brendan Eich: The infernal semicolon

#141
post #42

Is it me, or did the author tack on a new topic regarding the use of && and ||? The fact that they return the controlling operand is quite useful. Consider a situation where you want to check the property of an object, but don't know if that object is null: var foo = obj && obj.bar; I find this much more readable than: var foo = null; if (obj) { foo = obj.bar; } You can accomplish the same thing with a ternary operat…

empty array evaluates to true. :)

Re: Brendan Eich: The infernal semicolon

#142
post #111

Earlier quoted context omitted.

I’m sorry, but I don’t know what “FIY” means, what your point is, or how your comment is a reply to mine. Consider re-phrasing?

I misspelled FYI - "for your information". You said there are only downsides, and no advantages; I just told you what the claimed advantage is for "abusing" ASI. I hope you're not just being snarky.

I wasn’t. Apologies if it seemed mean-spirited — I only wanted to understand your point. I’m probably being thick, but I still don’t quite follow. It seems like you’re saying that if you leave semicolons out (relying on ASI), this makes “mistakes/missing semicolons easier to spot”? That doesn’t make sense to me. :-/

Re: Brendan Eich: The infernal semicolon

#143
post #137
post #47

Earlier quoted context omitted.

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

if (!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.

Yep, 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.
Post reply on HN