Live data from Hacker News

Crockford on Bootstrap's semicolon omission: “insanely stupid code”

github.com

161–170 of 224 posts

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#161
post #115

Earlier quoted context omitted.

I have never written a line of JS in my life, which hopefully qualifies me as an unbiased outsider, but I don't agree that that Crockford's position here on JSMin is the right thing to do. Here is what I see: @fat is not inserting "!" needlessly as a statement separator. The "!" is there for its proper purpose, as a "unary not" operation, which will short circuit the second operand of the "&&" when isActive is false.…

Here is what you're missing. Language lawyering is fine and dandy when you know exactly which compiler will be used and you know exactly how it works. But on the web that isn't the case. You can write code, but you have no control over what browsers, past, present and future, it will get run on. And it is your responsibility to make that work. According to the spec, you may be right. But in practice you're the one wh…

Crockford is releasing a tool which is compatible with his opinions, not with JavaScript. All browsers execute that code fine, present and past, and at least for the next decade or so.

Crockford can be an arrogant ass about this stuff, that's why jshint exists, because not agreeing with Crockford does not mean bad JavaScript, no matter what he would have you believe

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#162
post #120

Jacob is an idiot for writing code with a ridiculous fragile syntax that takes more effort to write in a vain effort to obtain "coolness" via winning a pointless language war that nobody on earth cares about. Crockford is an idiot for writing an JS minifier which explicitly promises to not break legal code but actually does, and then refusing to fix it because he's proud of his reputation for being an asshole. And ev…

> a pointless language war that nobody on earth cares about.

The comment section disagrees with you. He's just writing his damn code the way he wants to, which a large number of people seem to care about.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#163
post #59

Example when a semicolon is required in non-minimized javascript. alert(1) // add semi-colon here to make this code work (function(){alert(2)})()

There are other options here too but, given the OP, people seem to get irate when you use the features the language specification guarantees :'/

  alert(1)
  void function(){alert(2)}()

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#165

Should JSMin being enforcing the spec or good practice? My vote: Good practice Upvote replies to vote. Please don't down vote the replies so we get a clear picture.

It's obviously should be the spec + warnings for good practice.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#166
For those that agree with leaving semi-colons out of JavaScript that they write for projects, can you explain what the benefit of doing so actually is?

Seems like people are valuing aesthetics over producing code that works for 100% of the users/situations.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#167
I'm new to JavaScript, but from what I can tell, the no-semicolons style

- is incompatible with existing tools

- is incompatible in places with upcoming versions of JavaScript

- is harder to refactor, since you might need to add additional tokens to the beginning of lines depending on the previous lines

- is confusing to new JavaScript programmers, since

  + it goes against the recommendations of many of the most popular books

  + it requires adding tokens to the _beginning_ of lines in places, making the entire enterprise more challenging to learn and of dubious utility

  + it discards one of the attractive qualities of JavaScript for programmers of other languages: familiar syntax
And further, the use of constructs like

    !somethingHappened && otherwiseDo(x)
instead of

    if (!somethingHappened) {
        otherwiseDo(x)
    }
is bad practice in any language.

"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" - Brian Kernighan, "The Elements of Programming Style"

Although everyone has the right to maintain their projects with whichever style they prefer, given the above, I wonder why the chosen style was chosen.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#168
I happen to agree with Crockford on the omission of semicolons. I also have a strong opinion on clever code: you should always optimize for readability over aesthetics.

But... Crockford could have said it in a much more tactful way that could elicit a more positive response, spare the world from this sad discussion, as well as channel the man-hours dedicated to this into more useful endeavors.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#169
post #33

There's something horribly wrong with everything about this. Why is such a smart person as Crockford wasting his time arguing about semicolons in 2012? Why is this at the top of the most popular hacker website? Why are people writing detailed opinions about semicolons in this thread (with surely more to come?) One would hope that at least over time the bike sheds being argued about would start to at least evolve into…

> There's something horribly wrong with everything about this. The time is ripe for Dart!

Or to give back JavaScript its original syntax.

edit: now that I said that, it makes a lot of sense.

Re: Crockford on Bootstrap's semicolon omission: “insanely stupid code”

#170

It is a bug on JSMin. Minifying should never alter code behaviour.

The minification isn't breaking the code. The authors had an incorrect expectation of how JSMin would minify the code. By the very act of minifying code where new lines matter your are always potentially changing the behavior.

The minification is breaking the code. If a minifier takes valid JS in and produces JS that behaves differently from the input, then that minifier is broken, full stop. It doesn't matter how anyone personally feels about ASI; what matters is that ASI is a part of JS, so if you're making a tool that processes JS, you need to respect its rules.
Post reply on HN