TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

279 pointsby sferikabout 13 years ago

50 comments

gfodorabout 13 years ago
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?)<p>One would hope that at least over time the bike sheds being argued about would start to at least evolve into arguments about bike garages and eventually bike factories. But I guess the bike shed is forever a bike shed, as long as we're making bikes.<p>Whatever the next disruption is in software engineering, please dear God let it be immune-by-design to this type of distraction.
评论 #3842850 未加载
评论 #3842823 未加载
评论 #3842851 未加载
评论 #3843045 未加载
评论 #3843275 未加载
评论 #3842847 未加载
评论 #3842979 未加载
评论 #3842835 未加载
评论 #3844710 未加载
评论 #3844466 未加载
评论 #3843376 未加载
评论 #3847584 未加载
评论 #3843260 未加载
评论 #3842822 未加载
评论 #3843235 未加载
评论 #3843125 未加载
Lazareabout 13 years ago
Jacob is an idiot for writing code with a ridiculous fragile syntax that takes <i>more effort to write</i> in a vain effort to obtain "coolness" via winning a pointless language war that nobody on earth cares about.<p>Crockford is an idiot for writing an JS minifier which explicitly promises to <i>not</i> break legal code but actually does, and then refusing to fix it because he's proud of his reputation for being an asshole.<p>And everyone commenting on this post is an idiot for thinking that any of this is worth the pixels it takes to argue about it. And yes, that includes me.<p><i>sigh</i> This whole thing just makes my head hurt.
评论 #3843524 未加载
dhconnellyabout 13 years ago
I'm new to JavaScript, but from what I can tell, the no-semicolons style<p>- is incompatible with existing tools<p>- is incompatible in places with upcoming versions of JavaScript<p>- is harder to refactor, since you might need to add additional tokens to the beginning of lines depending on the previous lines<p>- is confusing to new JavaScript programmers, since<p><pre><code> + 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 </code></pre> And further, the use of constructs like<p><pre><code> !somethingHappened &#38;&#38; otherwiseDo(x) </code></pre> instead of<p><pre><code> if (!somethingHappened) { otherwiseDo(x) } </code></pre> is bad practice in any language.<p>"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"<p>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.
评论 #3843692 未加载
评论 #3844208 未加载
chrisguitarguyabout 13 years ago
Frankly this is less about semicolons and more about two people who both have strong opinions and feel that they need to act in a certain way.<p>It doesn't take a lot more effort to rephrase fat's response to be more cordial.<p><pre><code> "Hi @englishextra, those two lines are valid JavaScript. We try not to use semicolons whey they aren't necessary. See (insert link to the wiki). "JSMin doesn't perform well on bits of JS like this. Maybe you can discuss it with @douglascrockford ?" </code></pre> Flamewar avoided (probably) and more stuff getting done.
评论 #3842975 未加载
评论 #3842939 未加载
rocktronicaabout 13 years ago
Learning the minutiae of a language is important, sure, but I can't fathom why you'd willingly introduce unnecessary fragility or overthink into your codebase.<p>Ideally, your goal as a hacker is to make cool shit. Your goal is not syntax.
评论 #3843002 未加载
celticjamesabout 13 years ago
I think older programmers will side with Crockford and for good reason.<p>The bootstrap code makes assumptions about the future of the js spec and browser implementations that aren't safe. Young people don't remember the dark days of people writing js to leverage IE/Netscape specific bugs which then had to be turned into features because so much code existed in the wild that could be broken.<p>Crockford is a scarred veteran of the spec wars. I'm sure that when he sees young people trying to game spec/implementation ambiguities, he thinks, "Never again! Not on my watch!"<p>I think best practice is explicit, future-proofed code that doesn't tie the hands of spec authors or browser vendors. I know that Crockford's tool doesn't accept the current spec or browser behaviour, but his choice is informed by past experience and concern for the future. It's not just some random bug that he's too stupid or stubborn to fix.
jrockwayabout 13 years ago
Ah, I'm so glad that Github allows animations in pull request comments. They really increase the level of discourse!
评论 #3842967 未加载
leifabout 13 years ago
I am not experienced with javascript, so I don't understand this argument. Can someone please confirm the following, or explain what's going on?<p>Here is what I understand:<p>1. Javascript will add a phantom semicolon at the end of each line if it seems like you need it, for some definition of seems like. To me, it sounds like this is so that new HTML writers in '98 wouldn't see their pages blow up when they forgot a semicolon at the end of a script. It doesn't sound like professional programmers are expected to leave semicolons out on purpose (this is the opposite from python). The bootstrap authors took advantage of this because somehow screwing with the compiler is in vogue.<p>2. Crockford's tool broke when a semicolon was left out somewhere. I guess he didn't implement a proper js compiler that covers the entire language spec.<p>3. There's some business about unary and binary ! operators? Something about sticking a ! in front of your line lets you leave the semicolon off the end? This sounds utterly braindead to me. It's no fewer characters, and the thing you're typing is going really far away (at the beginning of a big block of code) from where it's actually meaningful to you (at the end). Also, it looks like it relies on some fairly convoluted unintended consequences of the spec, that may not be future-proof.<p>Here is my analysis, if the above understanding is true:<p>1. Bootstrap needs to fix their code. This business of the compiler sticking in semicolons where it thought you meant them is a crutch to prevent stupid errors from being fatal errors in the average case, but that doesn't mean they aren't errors. Be explicit.<p>2. Crockford should fix his tool soon, not complain about other people's code, and say "I'll fix it soon, but for now, here's a workaround: just put a semicolon in your code".<p>3. What the hell. Are people really doing this? Is the web one big obfuscated javascript competition? What happened to writing simple, explicit, readable, maintainable code? Are we really bickering over single characters and trying to play subtle tricks with language esoterica to save them like a bunch of 14-year old perl newbies? Man, I hope these morons aren't in charge of my bank account.<p>Overall, I'm with Crockford, but he doesn't need to be this much of a jerk about it.<p>Further analysis, now that I've read it with a decent (non-cell) data connection: allowing gifs in a public issue tracker is a terrible decision.
评论 #3843314 未加载
评论 #3843504 未加载
dantillbergabout 13 years ago
I wonder if the "insanely stupid" comment isn't about the omission of the semicolon but about the omission of "if". Since when is a good old-fashioned if-statement out of style?
ricardobeatabout 13 years ago
It <i>is</i> a bug on JSMin. Minifying should <i>never</i> alter code behaviour.
评论 #3843063 未加载
评论 #3842805 未加载
wpietriabout 13 years ago
Update: Bootstrap fixed their code as Crockford prefers. From <i>fat</i>'s comment circa 11 am PDT:<p><i>fwiw, this was patched in bootstrap way before i even encountered this issue - otherwise i wouldn't have closed it outright.<p>Sorry for the confusion everyone.<p>You can see the code here in 2.0.3: <a href="https://github.com/twitter/bootstrap/blob/2.0.3-wip/js/bootstrap-dropdown.js#L63" rel="nofollow">https://github.com/twitter/bootstrap/blob/2.0.3-wip/js/boots...</a><p>I still maintain this is a bug in jsmin, but as others have pointed out - mark and I do our best to make bootstrap flexible with other great tools out there (like jsmin). This includes adding semicolons where necessary or changing minor stylistic things.</i>
rbanffyabout 13 years ago
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.<p>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.
ronaldjabout 13 years ago
That code is bad for more reasons than the semicolon omission.
greghinchabout 13 years ago
While this "argument" has prompted several lol's on my part, JS really needs some equivalent of PEP8<p>And if you don't use semicolons you are an asshole.
评论 #3843187 未加载
Sephrabout 13 years ago
&#62; <i>! is not intended to be a statement separator. ; is.</i><p>Which is why there is a line break there. He's far too stubborn to realize that JSMin is at fault for not being able to correctly parse JavaScript.
评论 #3842810 未加载
评论 #3842814 未加载
alecperkinsabout 13 years ago
“…Explicit is better than implicit… Readability counts… In the face of ambiguity, refuse the temptation to guess. There should be one—and preferably only one—obvious way to do it…” — The Zen of Python<p>Ironically, the Zen of Python supports using semicolons in JavaScript. Also, both sides come off like children, but at least Crockford's opinion seems a little less selfish. It's like politics, with the difference being in their premises so they'll never agree.<p>Also, why can't I (or anyone else) resist commenting on this rather pointless debate? I am disappointed in my weakness.
stiffabout 13 years ago
It is hard for me to understand how one could make so many things in a programming language completely arbitrary - I mean it is natural for a language designer to have some vision of how the language will be used by other people, how will the common structure of the programs look like, but JavaScript looks like such a vision never existed, there are often several ways of doing the most basic things (writing vs. omitting semicolons mentioned here, writing vs. omitting "var", but above all else 1000 of ways of doing OO, all with it's own problems) and no easy ways at all of doing other very basic things (modules/namespacing). As a result you can find 10 or 20 programs written in JavaScript where each looks like it was written in a quite different language. Maybe it was an attempt to make an "easy" language for non-programmers (I doubt even this goal was in the end achieved), but as a primary language for programming client-side applications it is a utter disappointment. Not that I necessarily blame the JavaScript creator, I am sure there were plenty of corporate pressures involved and other factors of corporate/economic nature.<p>I wish we could get some other programming language implemented in all the major browsers, then at least in the perspective of the next 10 years we could completely get rid of JavaScript, I am not sure if it possible to really improve the situation in a radical way just via incremental changes to the existing design.
kellysuttonabout 13 years ago
Crockford wrote JavaScript: The Good Parts. He did not write JavaScript: The Cool Parts.
magicalistabout 13 years ago
if there's anything worse than crockford being a jerk, it's the self-aggrandizing asi crowd. Let's not give either any attention.
评论 #3842870 未加载
sferikabout 13 years ago
For a good explanation of why it's a good idea to always use semicolons in your JavaScript, take a look at: <a href="http://lucumr.pocoo.org/2011/2/6/automatic-semicolon-insertion/" rel="nofollow">http://lucumr.pocoo.org/2011/2/6/automatic-semicolon-inserti...</a>
评论 #3842788 未加载
mericabout 13 years ago
Example when a semicolon is <i>required</i> in non-minimized javascript.<p><pre><code> alert(1) // add semi-colon here to make this code work (function(){alert(2)})()</code></pre>
评论 #3843525 未加载
评论 #3843015 未加载
rasurabout 13 years ago
Excellent - another internet cock-fight, with both sides managing to act like total cocks..<p>What would be better is for both sides to fix their code: Crockford to fix minify for the edge cases like this (result: better, more robust code equals a win), and the twitter boys to add a semicolon for these edge cases (result: better, more robust code equals a win).<p>But instead, as usual on the internet, it's just devolving into lots of "waah waah waah".
评论 #3844762 未加载
jcoffeyabout 13 years ago
What is insanely stupid is abusing the logical bitwise &#38;&#38; operator rather than signifying their intent using a plain old if statement like the language intended.
joshonthewebabout 13 years ago
I'm sure this thread is going to be a good, old fashioned flame war. Let the games begin.
评论 #3842907 未加载
brown9-2about 13 years ago
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?<p>Seems like people are valuing aesthetics over producing code that works for 100% of the users/situations.
评论 #3843727 未加载
Yarnageabout 13 years ago
I agree with Crockford.
_rknLAabout 13 years ago
Why is this discussion about semi-colon insertion and not about the use of short-circuiting as a replacement for specific 'if' statements and general inconsistency in the project?<p><a href="https://github.com/twitter/bootstrap/blob/master/js/bootstrap-carousel.js#L91" rel="nofollow">https://github.com/twitter/bootstrap/blob/master/js/bootstra...</a><p><a href="https://github.com/twitter/bootstrap/blob/master/js/bootstrap-modal.js#L61" rel="nofollow">https://github.com/twitter/bootstrap/blob/master/js/bootstra...</a><p>(Incidentally, would lines 54/56 of bootstrap-modal suffer from the same problem? Or does the fact that the last function call on line 54 is already in an &#38;&#38; expression change things)<p>I'm kind of surprised that the bug wasn't fixed by changing the line to `isActive || $parent.toggleClass('open')` as is done here <a href="https://github.com/twitter/bootstrap/blob/master/js/bootstrap-alert.js#L52" rel="nofollow">https://github.com/twitter/bootstrap/blob/master/js/bootstra...</a>
gormabout 13 years ago
The use of semicolon as best practice was sorted out years ago in the js community. Crockford has all his rights to tell these guys to sharpen up because that "fat" character is obviously a python smuch with no knowledge of JS history or respect for elders.
smhinseyabout 13 years ago
Funny, I was just checking out Derby and noticed that their examples follow this style.
评论 #3842752 未加载
IsaacSchlueterabout 13 years ago
My comment from the thread, buried under many pages of meme gifs:<p>&#62;&#62;&#62;<p>@douglascrockford If TC-39 makes ! an infix operator, which causes \n to not terminate the statement, then that will be a syntax change that is incompatible with current code in the wild, which would be an insanely stupid move on their part.<p>The fact of the matter is that JSMin isn't parsing JavaScript correctly. I thought the separation of concerns was that JSLint tells you about stupid code, and JSMin correctly parses JavaScript according to the ES standard and minifies it safely.<p>&#62;&#62;&#62;
slantyyzabout 13 years ago
Am I missing something? Aren't Bootstrap and JSMin open source? Instead of focusing on coding philosophies, someone can simply fork JSMin's source and make the appropriate patch, or make a fork of Bootstrap that has JSMin friendly code.<p>Regardless of our many diverse opinions, Crockford and Fat are entitled to maintain their own libraries in whatever fashion they desire. The fact that they made the libraries open source means "if you don't like my code or the way it works, here's my code, customize it and leave me alone".
tbranyenabout 13 years ago
I think the stupidity here is entirely isolated to using JSMin.
评论 #3843033 未加载
biojazzardabout 13 years ago
If I remember well, bootstrap is using cat &#38; uglyfy, not JSmin. Every jQuery plugging in BS starts with a semicolon. The Battle of the blind egos.
alexchamberlainabout 13 years ago
Should JSMin being enforcing the spec or good practice?<p>My vote: Good practice<p>Upvote replies to vote. Please don't down vote the replies so we get a clear picture.
评论 #3843642 未加载
评论 #3845119 未加载
评论 #3845118 未加载
评论 #3843505 未加载
评论 #3843509 未加载
jhuniabout 13 years ago
I am so glad that I am a Lisper. I haven't dealt with issues of text file size or syntactic standards for at least a year.
seandonabout 13 years ago
I don't get it, @fat never said anything negative/positive towards Crockford. Why is this even a thread??
noonespecialabout 13 years ago
"Be liberal in what you accept, and conservative in what you send." <a href="http://en.wikipedia.org/wiki/Robustness_principle" rel="nofollow">http://en.wikipedia.org/wiki/Robustness_principle</a><p>Its like the golden rule for software. It generally stops nonsense like this cold.
评论 #3845452 未加载
评论 #3845455 未加载
peregrineabout 13 years ago
Real question is... why not just use UglifyJS or any one of the other js minifiers? So what Crockford is opinionated about JS, we all know this. Don't use his products if you don't like his opinions.
pbreitabout 13 years ago
The obvious thing to do is:<p>1) JSmin should be modified to handle Bootstrap-style semi-colon-ing<p>2) Bootstrap should adopt the more commonly understood semi-colon-ing
grover3333about 13 years ago
Jacob/Fat was trying to minimize the code before it was run through minimizer and is surprised at the results?<p>Sounds like another emotional issue.
biafraabout 13 years ago
If there is a tool to insert semicolons in all the right places, you could use that before using jsmin. Would that help?
评论 #3843083 未加载
dubcanadaabout 13 years ago
How many times must this bush be beaten. I've read people complaining about no semicolons in javascript for ages.<p>Get over it...
goronbjornabout 13 years ago
It's called forking.
bkorteabout 13 years ago
Oooh, developer drama.
bbayerabout 13 years ago
you don't have to use linebreaks either but people use it. There are lots of good practices making code easy to use, read and maintain. So just put f.. semicolon.
joshonthewebabout 13 years ago
yes, yes, yes.
ellie42about 13 years ago
That's really stupid. There's no plausible reason that the end of that method shouldn't have a semi-colon. I honestly wouldn't advise anyone use Twitter Bootstrap. You should always use semicolons in Javascript even if you're hippie. Hippies use coffeescript.<p>And I think Google's style guide[1] is prevail over Github's style guide[2].<p>[1] <a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons" rel="nofollow">http://google-styleguide.googlecode.com/svn/trunk/javascript...</a> [2] <a href="https://github.com/styleguide/javascript" rel="nofollow">https://github.com/styleguide/javascript</a>
drivebyacct2about 13 years ago
Crockford's stance is annoying purely because it's pedantic and because there are <i>many</i> libraries that embrace this style. We use django_compressor and found bugs from the compressor that uses Jsmin. So I have to use something else to compress them before hand.<p>Are there compressors that use the syntax tree rather than transforming the source?
评论 #3842760 未加载
评论 #3842968 未加载
dreamdu5tabout 13 years ago
I don't care what Crockford thinks. He's irrelevant and his opinions are often confused with expertise.
shpoonjabout 13 years ago
What a child... Has anyone read the GitHub style guide? 'Do your best to never use a semicolon. This means avoiding them at line breaks and avoiding multi-statement lines.'<p>Grow up Crockford. Do research before you post. Stop assuming because you supposedly once knew how to do something, you still do, and always will. Times change.<p>However, this is all very exciting. It gives Twitter, or whatever other start up, an opportunity to replace an outdated piece of software by a nut case!
评论 #3843165 未加载
评论 #3843183 未加载
评论 #3843169 未加载