Live data from Hacker News

Brendan Eich: The infernal semicolon

brendaneich.com

131–140 of 143 posts

Re: Brendan Eich: The infernal semicolon

#131
This entire debate is sad to me. It's sad - as a JS outsider - because it truly smacks of religious dogma. People have these debates about The One True Brace Style as well, but it all amounts to masturbation.

The amount of hair-pulling and whining over 1 byte really turns me off from the JS community as a whole. I respect BE's weighing in on this, and I respect people for disregarding his advice. The bottom line is: do whatever the hell you want and don't let anyone shove their opinions down your throat. Why can't we be happy with that?

The little JS I've written has been filled with semicolons. Yours may or may not be. If I work on your project and you don't use semicolons, I'll adapt. If you work on mine, you'll adapt. But I won't try to convince you to use my style on your project or vice versa.

Can't we move on from this pointless debate? Nobody will win, but in the end everyone will lose.

Re: Brendan Eich: The infernal semicolon

#132
Guys, more background from 'Fat' on why he doesn't use semicolons written back in October 31st 2011: http://wordsbyf.at/2011/10/31/i-dont-write-javascript/

Quotes: On the use of '&&' instead of an 'if' statement: "If you were really having fun with it you could lose the if all together... Each is perfectly valid. Each behaves the same. It’s just a matter of preference and finding the style that makes most sense to you." JSLint is described as a "unnecessarily strict linter". "The majority of lines however don’t end with semicolons because they simply aren’t necessary and I prefer the minimalist aesthetic. For me, \n character is enough and the semicolon character is redundant."

... IMHO: Don't be a JavaScript hipster. Add semi-colons.

Re: Brendan Eich: The infernal semicolon

#133

Earlier quoted context omitted.

That is what surprised me a lot. That there would be so much defense of the practice. I work on C/C++ for a living in enterprise environment and there are style rules followed diligently. Every one knows that there can be lot of cool/hipster code written with C/C++ but no one does because of the maintenance concerns. Writing code is much easier than maintaining it.

What are the universally accepted style rules for C/C++? Every organization I have worked in has had to develop their own guidelines around style in C/C++. What really surprises me is that such a large number of people are quick to attack someone for writing legal code simply because they disagree with the style used. It feels awfully close to attacking someone for using a different bracing style from your preferred…

The feature in question is intended as an error correction for those cases where the programmer accidentally left out newline. A misguided feature maybe, but it's clearly being abused by intentionally leaving out every (or most) newlines.

Re: Brendan Eich: The infernal semicolon

#134

For what it's worth, both libraries in question realigned their egos, despite trolling from the likes of madrobby. https://github.com/twitter/bootstrap/commit/575f18aaf49abb02... https://github.com/douglascrockford/JSMin/commit/5ca277ea452...

So the fuse has burned out, but the fire's already burning. Ah well.

At least some good has come of this, even if it did come with the baggage of a massive Internet Argument.

Re: Brendan Eich: The infernal semicolon

#135
post #86
post #33

Heh, I was waiting for this post. Coming in the next 24 hours: - "Why I use minimal semi-colons in Javascript" - "ASI is broken but I like it" Honestly I'm shocked at the defense of this practice (of ASI "abusage"). It speaks loudly to Jacob's (fat@githib) ranking of ego-stroking and showboating over creating readable code, particularly for a library "Designed for everyone, everywhere" [1]. I'm confounded that such a…

The GitHub style guide recommends the opposite: "Do your best to never use a semicolon. This means avoiding them at line breaks and avoiding multi-statement lines. For more info, read Mislav's blog post [2]." FWIW, I agree with the Google style guide. Maybe I'm interpreting it wrong, but ASI struck me as a fail-safe to protect coders that forgot the occasional semicolon and was later mis-identified as a feature. Havi…

FWIW the GitHub JavaScript style guide also recommends that you don't write JavaScript _at all_, unless you can't help it.

Re: Brendan Eich: The infernal semicolon

#136

Earlier quoted context omitted.

That is what surprised me a lot. That there would be so much defense of the practice. I work on C/C++ for a living in enterprise environment and there are style rules followed diligently. Every one knows that there can be lot of cool/hipster code written with C/C++ but no one does because of the maintenance concerns. Writing code is much easier than maintaining it.

What are the universally accepted style rules for C/C++? Every organization I have worked in has had to develop their own guidelines around style in C/C++. What really surprises me is that such a large number of people are quick to attack someone for writing legal code simply because they disagree with the style used. It feels awfully close to attacking someone for using a different bracing style from your preferred…

> What are the universally accepted style rules for C/C++?

Whenever I've been asked this, I've pointed people at the JSF-AV coding standards or MISRA.

> What really surprises me is that such a large number of people are quick to attack someone for writing legal code simply because they disagree with the style used.

The important part of the lifecycle of a piece of code isn't the writing of it. It's the maintaining and rewriting that matters. If one coding style makes it easier to introduce errors than an alternative, that's a bad thing. It's not an aesthetic concern. Semicolon-less JS is demonstrably less robust.

Re: Brendan Eich: The infernal semicolon

#137
post #47
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…

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.

Re: Brendan Eich: The infernal semicolon

#138
Languages should either (1) treat newline as a statement delimiter (as in Python) or (2) not do so and instead treat some other character (e.g. ";") as a statement delimiter (as in C etc).

JavaScript falls between two stools and that's bound to cause problems.

Re: Brendan Eich: The infernal semicolon

#139

The purpose of the semicolon in javascript is to eliminate ambiguity. Choosing not to avail yourself is like driving without a seatbelt -- of course it's possible, but I always thought the job of a programmer was to be as unambiguous as possible. You're not the only person reading your code. Your code isn't just being parsed by five wholly different javascript engines, it's also being parsed by the brains of every pr…

When I program in C-syntax languages, I always surround loop and conditional blocks with braces, even if they have a single line of code. Even though these languages allow braces to be omitted, I consider it bad style, and error prone (although I have never seen a real bug where a programmer made an error of including multiple statements without braces). The languages do allow this style, and however distasteful I personally find it, I would expect compilers to handle it properly.

I think the same should apply here, the minifier should handle the language as specified, if it can't then it is has a bug.

Re: Brendan Eich: The infernal semicolon

#140
post #33

Heh, I was waiting for this post. Coming in the next 24 hours: - "Why I use minimal semi-colons in Javascript" - "ASI is broken but I like it" Honestly I'm shocked at the defense of this practice (of ASI "abusage"). It speaks loudly to Jacob's (fat@githib) ranking of ego-stroking and showboating over creating readable code, particularly for a library "Designed for everyone, everywhere" [1]. I'm confounded that such a…

I am currently writing the a style guide (for a small agency), and I have added semi-colons as preferred for JavaScript. And abusing the && operator like in the now infamous code snippet is definitely out.

Our code needs to be maintainable for inexperienced developers. I don't want to make it easier for them to make mistakes and I don't want them to ponder rare (though valid) syntax. I feel this is a valid reason to maintain this rule.

  // This we can all understand
  clearMenus();
  if(isActive) {
    $parent.toggleClass('open');
  }
Once a developer understands ASI and other details he is free to feel elated with his new-found knowledge, but I'd prefer if he choses to know rather than to apply these powers.
Post reply on HN