Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Bootstrap's maintainer hates the semicolon (github.com/twitter)
173 points by wyuenho on Feb 13, 2012 | hide | past | favorite | 133 comments


Thanks for drawing my attention to this. Currently, I maintain a separate branch simply for adding the missing semicolons so that I can link the individual bootstrap files with my project. It's been quite annoying and I now know that the annoyance may not go away anytime soon.

I hate these ideologues. But this is the trouble with JS I guess. I actually love javascript because of the highly dynamic nature of it. But that dynamism also lends itself to these kind of problems. I don't know of any other language where people can CHOOSE to follow syntax. Part of the problem is the awkward interpreter specs I guess. But also, with JS seems like everyone has an opinion :)


Relying on multiple different parser's implementation of the "auto semicolon insertion guesser" feature seems insane to me.

I'm a python/haskell guy too, I hate semicolons. But I'll put up with them because javascript needs them, it doesn't enforce them, but to write sane, maintainable code it really needs them.

Javascript is enough of a mess, this kind of thing just throws gas on the fire.

Have you published your branch? I think it would be very useful.


JavaScript doesn't need them any more than Python does; they're used almost always simply because people don't know the (simple) rules of when statements end.


Or because people simply don't want to have to think about when statements end.

I know the semicolon insertion rules, because I'm obsessive-compulsive like that. In any team I lead, any software I write, and any open-source project I maintain, the coding standard will be "Terminate all your statements with semicolons."

Why? Because my job is to make less work for people, not more. I could give them a list of 4 rules, often each having a list of a half dozen+ tokens, and say "memorize these, or you're not a professional JavaScript programmer". Or I could say "Terminate your statements with semicolons", and there's one rule, the same as in many other languages, for them to memorize.

Other projects are free to do whatever they want with their coding standards, and if they want to make things complicated to show how 1337 they are or just because they think it looks pretty, fine. But of all the things you need to worry about to be a good frontend engineer, where to put the semicolons seems like the stupidest possible one.


Please read http://blog.izs.me/post/2353458699/an-open-letter-to-javascr... again, especially the restricted production part. Using semicolons everywhere doesn't cover your ass in those cases. Granted, I've never ever encountered these, but still -- it's not as simple as you make it out to be.


> Granted, I've never ever encountered these, but still -- it's not as simple as you make it out to be.

There's one and only one of these cases which I've seen (and I'd see) happen: `return`, for users of Allman, while that is completely nutty (just as Allman) some people will write:

    return
    {
        key: value
    };
even though they're defining an object literal not a scope. The result is returning immediately (undefined) and dropping the object in space.

`throw` would be really weird, it may happen with a labelled break or continue but I've yet to see those ever used at all (so a user of these probably wouldn't fuck up the label, plus that label would become a bareword which most static analyzers would trivially see) and postfix operators outside of continuated expressions (e.g. function calls) are unlikely to be split.

I've been bitten more often by not having inserted semicolons than by any of those.


That's covered by other really common coding standards, eg. "put braces and brackets on the same line as the token that comes before them", "don't add linebreaks unless necessary to stay under 80 chars", and "break after binary operators rather than before them".

The point's to minimize the amount of additional complexity that developers have to memorize. The set of rules above is very similar to what you see in pretty much any Algol-derived language; most developers already have it burned into their fingers. The set of rules necessary to code safely without semicolons is very specific to JavaScript, and to a very idiosyncratic style of JS at that.


> I don't know of any other language where people can CHOOSE to follow syntax.

Your argument is incorrect. :) Omitting semicolons is perfectly valid and correct syntax. The spec is explicit about it being allowed and how the code shall be interpreted: http://es5.github.com/

It may be a good rule of thumb to use the semicolons, because you have to be careful without them, but in the end it's a choice based on team preference. If you are a very pertinent and careful type of person, and you don't have any rabid illiterates on your team, going without semicolons makes perfect sense.


The spec has provisions for automatic semicolon insertion that need to be considered carefully before deciding to completely ignore them. Now consider that http://twitter.github.com/bootstrap/index.html says the following:

"Bootstrap is designed to help people of all skill level—designer or developer, huge nerd or early beginner. Use it as a complete kit or use to start something more complex."

So: 1. "illiterates" are welcome to use it. 2. If the goals are to be met, do not assume anything that can be interpreted differently by different players.


> If you are a very pertinent and careful type of person, and you don't have any rabid illiterates on your team, going without semicolons makes perfect sense.

Why does it make perfect sense? There's nothing wrong with including them, and I find it reduces the amount of thinking you need to do. JavaScript has C-like syntax; it should end its lines with semicolons and it's a mistake that it doesn't always require them.


Your branch can become the new public useful one perhaps?


Yeah, I've been thinking about doing this. I was kinda hoping that the missing semicolons were just an oversight on the bootstrap teams part.

Now that I know there is some demand for a branch of this sort, I'll share it ASAP.

EDIT: the repo is at https://github.com/rajivnavada/bootstrap


Adding semicolons is also an ideology.


You can do it in Ruby and lots of other languages


Ruby, Python, Go, JavaScript, Bash, even Clojure -- kinda.

https://gist.github.com/1815639

Of course, unless you're the sole writer and reader of the code, it's generally good to follow the common practices that evolved around the particular language.


Just becuse it is in the language spec does not mean that you should use it - Arithmetic IF's in Fortran are a good example.


You can use semicolons in python. You have to use them if you want multiple statements in one line..


> I don't know of any other language where people can CHOOSE to follow syntax.

You should check out Lisp macros ;)


I wouldn't see any significant problem with a policy of omitting semi-colons when there's no risk of ambiguity, but turning the omission of semi-colons into a religion? That's enough to make me question what other nutty peculiarities exist in his coding philosophy, and therefore whether I'd dare risk my own projects using his library.


It's just embracing the ASI. Nothing wrong with it. On the contrary, the understanding necessary to use it implies good knowledge of the language.


And is therefore more expensive to maintain.


It's probably less expensive to maintain, because programmers' brain reading the code while not having to parse the extra image information - which semicolons are, and they add a lot of clutter - gets less tired and in turn is less prone to make errors in other coding areas.

I see two camps here - people who fear the unknown or come from semicolon-mandatory languages and can't get used to the semicolon-less style, and informed people who don't fear to embrace what is aesthetically more pleasing and logically more sound, despite the persecution by the members of the first camp, which I'd say also happens to be more religion-prone.


I try to assume good faith with HN comments, but this smells like a troll.

In JavaScript, semicolons reduce ambiguity. Whether you know the semicolon rules in the language or not is immaterial to reducing ambiguity, similar to how defensive parenthesization is helpful regardless of whether you know the order of operations of a given language by heart. This is why the prevailing wisdom is to always use semicolons: principle of least surprise.

The nonsense about "persecution" and "more religion-prone" is just that. "Informed people" -- "aesthetically more pleasing" -- "logically more sound" -- ad hominem and begging-the-question horseshit. Do better.


I happen to have a definite, knock-down argument in favour of a particular semi-column free style: mandatory indentation (which also eliminates curly braces).

http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-i...

I'll grant you that's not a large scale experiment on a peer reviewed paper. But I trust Chris Okasaki on this one, and to me, his experiment counts as strong evidence against semicolons and brackets. (Specifically, semicolons and brackets are error-prone, especially for beginners.)

Now for Javascript, I'd probably write the semicolons. Because there is some ambiguity in the way we humans would parse Javascript without semicolons. But really, the root of the problem is that Javascript's syntax is suboptimal. Sure, Dennis Ritchie didn't know better at the time he wrote C, but this is no longer an excuse.

If I had a say, I'd simply write an alternative syntax with mandatory indentation. It's not hard[1]. If Bootsrap's maintainer dislike semicolons so much, he probably should do so as well. He will likely lose contributors, but someone who cannot get past a Python-like syntax is probably not someone he would want to work with anyway.

[1]: http://www.tinlizzie.org/ometa/ (Quite the tool for the job. Plus, it already features a Javascript parser you can modify.)


Downvote? What could possibly warrant that? Not that I'm offended, but I am confused. I thought I was accurate and relevant. Did I get some fact wrong? Or did I say something offensive?

Re-reading my post, I find 2 potentially offensive excerpts:

"Dennis Ritchie didn't know better" Assuming mandatory indentation is superior, this one is flatly true (and there are other things to be said about the syntax of types). But I'm not saying he could have known better. As far as I know, no one knew better at the time.

"someone who cannot get past a Python-like syntax is probably not someone he would want to work with anyway" I apologize for this one, but I am personally fed up with people who won't use provably superior technology just because it would break their habits. Enforcing indentation in Javascript would be a minor syntax change, that can be learned in minutes and mastered in a day. I'd be wary of someone who refuses to make the leap despite the evidence for it. I must admit however that I'd understand if they just didn't believe in the evidence. (but then we can talk).


That's a score for coffeescript, but you don't want to start that discussion here...


Yes, anything you can do to reduce ambiguity in the code will not only make it easier for the people who come after you, but it will reduce ambiguity between your mind and the implementation you're coding.


That's exactly the approach of no-semicolon javascript - only use them where they are needed to avoid ambiguity.


> Do better.

exactly. be an evangelist, not a brogrammer.


You don't think there's a third camp of people who know all about ASI but choose not to use it because their cognitive capacity (and that of their teammates, who may not spend weekends reading the ECMAScript spec) is better spent elsewhere?


It's probably less expensive to maintain, because programmers' brain reading the code while not having to parse the extra image information

In your estimation, is there a difference in experience between those JS coders who are knowledgeable of ASI and those who aren't?


> It's just embracing the ASI.

As opposed to embracing the rationally derived and broadly accepted coding guidelines used by over 99% of open-sourced javascript projects.

I could embrace linguistic documentation and still speak a form of English that would be unnecessarily dense or terse, or just plain incomprehensible to 99% of the English speaking public.


That's been done, and it's comprehensible to 90-95% on the other side. Bad analogy ;)

http://en.wikipedia.org/wiki/Differences_between_Afrikaans_a...


The point of programming is not to show off how well you know the language, else we'd be writing our C in trigrams and our JS in []()+!:

http://discogscounter.getfreehosting.co.uk/js-noalnum.php


Reductio ad absurdum.

The intention is to make code easier to read and type. The mental effort is the same.


And when legitimate bug reports are filed, they get ignored or worse, mischaracterised as the impure attacking his religion.


He wrote a blog post about this a while ago, I don't really get his reasoning but I guess he's happy with his decisions:

http://www.wordsbyf.at/2011/10/31/i-dont-write-javascript/


This blog post accurately states the broken idea:

> 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.

Part of being a good steward to a successful project is realizing that writing code for yourself is a Bad Idea™. If thousands of people are using your code, then write your code for maximum clarity, not your personal preference of how to get clever within the spec.

Code is harder to read than to write. To borrow a line from Jacob Kaplan-Moss, if I write the cleverest code that I am able to, then by definition I won't be able to understand it later.

This semicolon approach isn't invalid, but it is clearly a source of confusion, and it requires that users comprehend the choice and the tradeoffs. This seems like a poor choice for a framework whose audience is largely people who don't grok this stuff and are bolting it on wholesale.

<3 bootstrap, just my $0.02.


The quote is Kernighan's I think: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."


It is a valuable and documented code quality. http://en.wikipedia.org/wiki/Principle_of_least_astonishment

Principle of least astonishment (POLA) was also a core design decision behind ruby. http://en.wikipedia.org/wiki/Ruby_(programming_language)#Phi...


Leaving semi-colons out is not clever, it's just understanding where you need them instead of shooting blindly.


Does it hurt to have extra semi-colons? Maybe you have some empty statements. Does it hurt to have too few? Well, if you either do not know what you're doing, or someone maintaining doesn't understand what you did, etc., then yes.


Extra semicolons can cause problems. If "someone who doesn't know what they're doing" starts putting semicolons after randomly chosen tokens, it will absolutely break your program. You need to understand statement boundaries whether or not you explicitly mark them with semicolons.


Replying to myself because I decided I have more to say:

Imagine if a coder wrote a big huffy blog post declaring that he was only going to use single-character variables everywhere because it was more "minimalist" than using descriptive variables. He'd be hanged.

Obviously what "fat" is deciding to do with semicolons is less annoying than the strawman I just made up, but I don't think it's entirely dissimilar. The Javascript spec doesn't say that you must use descriptive variables, and using single character variables is certainly valid. However, it's an established convention that we just don't do that, because people find it irritating.

Basically this just comes down to "plays well with others".


I have to wonder if this is just some invented crisis so this guy can place himself into the tradition of the byte-counting olden days.


This one bit me the other day and forced me to switch JavaScript compressors because the one I was using (it was python-based) didn't get the IIFE (http://benalman.com/news/2010/11/immediately-invoked-functio...) right when appending files together.

In this blog posting Jacob writes:

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.

He then points to the izs blog posting about it:

http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...

Jacob calls it more 'minimalist' however it does require you to know (and think about) the rules of when Javascript accepts a newline as a line terminator and when it doesn't. In terms of cognitive minimalism 'semis-everywhere' wins. @izs even acknowledges that part of the advantage is forcing the developer to learn:

To the extent that there is an objectively “better” choice, it appears to me that the minimal-semicolon/comma-first style is slightly superior, both because it is fundamentally more scannable and because it encourages programmers to better understand the language they use.

and later:

If you don’t understand how statements in JavaScript are terminated, then you just don’t know JavaScript very well, and shouldn’t write JavaScript programs professionally without supervision, and you definitely should not tell anyone else how to write their JavaScript programs.

He excludes the possibility that you might understand the rules and still prefer to put them everywhere. So all people who disagree with his choice (which he admitted was only slightly better) tend to get categorized as people who don't understand JavaScript very well and we get a new holy war. The fact that all of the JS noobs are lumped on one side of the argument means it's not cool and we can dismiss a well reasoned opinion as ignorance.

All this being said, I personally don't care strongly one way or the other.


And possibly some reasons why leaving semicolons off can make his or others' lives a bit annoying:

http://bonsaiden.github.com/JavaScript-Garden/#core.semicolo...


That's a part of JS Garden I don't agree with. Leaving semi-colons only changes behaviour if your code is wrong in the first place...


How is the following code "wrong"?

  var foo = function() {
  } // parse error, semicolon expected
  test()
For completeness' sake, this example works:

  var foo = function() {
  }; // no error, parser continues
  test()


This is utterly stupid. And the example he cites for why he prefers an odd function syntax doesn't cause errors..... if you use semicolons.

JavaScript interpreters insert semicolons. If you abuse this, you'll end up with unpredictable results like his function example.


The results aren't unpredictable - they're specified exactly, which makes it safe to omit semicolons except where necessary.

You might not know that the return statement is a restricted production, but you do know when you shouldn't immediately follow it with a linebreak.

Similarly, if you see a line beginning with ( or [ which isn't a continuation of the statement on the previous line, stick a semicolon in front of it, or in the case of a wrapped function() {}, use one of the other means of telling the parser it's a function expression. There are other restricted productions, but you just solved every non return-followed-by-linebreak ASI issue I've ever seen in the wild.


Yes, it's specified, but you can avoid any confusion and make easier to read code by just using semicolons. It's what's called a "best practice".


Thanks for the kind words. I've been writing javascript like this for more than a year without any trouble. It's not confusing at all, you just need to sit for 5 minutes and understand ASI.

I'd bet with confidence that 90% of programmers out there don't know if a semicolon is needed after a function declaration. They just put it in there blindly, then some day they find a bug because they "forgot" a semi-colon somewhere.


I understand JS just fine, and I know where semicolons are needed and where they aren't. But minimalism is not a reason to avoid using them. Feeling you're more clever because you leave them off doesn't make you so. JS interpreters use semicolon insertion: it's not that they're not needed, it's that they're being added for you if you don't use them.


It's not about being clever. As I've said before, it takes all of 10 minutes to understand it, but nobody cares. There is nothing magic about ASI, a line break ends a statement in 99% of the cases.


The question is, why should I care to not end a statement in a semicolon? I gain no advantage. Any speed in coding advantage comes from my editor, not omitting semicolons. Most people commenting here understand ASI. Simply understanding something doesn't make it better. I could write code like I'm a bizarre minifier-human hybrid if I really wanted to. What would that gain me?

Indenting isn't necessary either. Less necessary even than semicolons. We do it for a reason. Maintainability, understandability.

The less ambiguity the better.

The only advantage you get is you can see a thread like this and say I DON'T USE SEMICOLONS CUZ I BE SO SMART I GET JS SO GOOD. But you're not coding to work with other people. It helps no one else, it's esoteric and unnecessary.


I don't see the need for personal offense here. You don't like it, ok, but it's a perfectly reasonable, rational and valid approach. NPM, the node.js package manager with +7000 packages published, is written in ths style.


I'm not taking personal offense, I'm just saying 1. It's not perfectly reasonable. 2. It's not rational 3. It is valid, but it is not sound. It's not an advantageous approach. It is annoying to other coders.


Maybe this kind of reasoning explains why their API is such garbage.


I agree. As some-one who has just finished with a large-ish project using bootstrap, I can say that one of the worst parts of it is its js api.


I almost regret my incendiary comment above. I made it first thing upon waking up... However, I was referring to the actual Twitter API, which seems to have frequent issues. If the Twitter engineering culture is based on a bunch of "because I like it this way" solutions rather than "because this is the right way to do it," it may explain some of what I perceive to be their shortcomings.

One should be self-expressive, but I don't think syntax is an opportunity to be so. Regardless of whether it works a certain way, there's very likely an objectively right way for it to be done.


One should be self-expressive, but I don't think syntax is an opportunity to be so.

Sure it is. Textual expression is a function of both form (syntax) and content (characters). Not only that, but TMTOWTDI enforces overlap between the right way to do something and the coding preferences of the implementor.


Okay, fine. It's some form of self expressions; but it's petty self expression. Writing in all lowercase is unlikely to establish you among the classics, even if your readers can still understand all of your sentences. That sort of "creative syntax" would be expected in graffiti, not Hemingway.


Can you unpack that? At a glance, it looks okay, but I haven't actually done anything with the JS API yet.


Idealism is like sex: everyone can enjoy it in private, but you shouldn't do it in public unless it's your whole reason for existing.

From this we deduce that Richard Stallman is really Ron Jeremy.


If you're going to use JS, you're not allowed to change things like this. It just causes problems for people.

Easy solution, use CoffeeScript and have it compile down to JS. My favorite feature of CoffeeScript is the ruby/python line conventions spacing (2 spaces, no tabs), and no semicolons.

They're already compiling the CSS from Less. Seems natural to add CoffeeScript to the chain.


For the sake of completeness, PEP8 actually says 'Use 4 spaces per indentation level'


He's not changing anything, and he's not relying on weird browser implementations - it's part of the spec.

I hate unnecessary semicolons too. Though I deal with them by including them everywhere, but making them hard to see in my editor ;)


alternatively, use JSLint


I much prefer JSHint. JSLint is draconian, and has some borderline insane decisions (it complains if you don't declare your vars at the top of a block—is this 1980?).

And yes, I realise that some of these options can be turned off—but JSHint has better defaults.


There is a reason for the insanity you are complaining about. The vars are effectively hoisted there by the interpreter anyway, by pulling them to the top of the block you remove a possible point of confusion, and more importantly a possible point of bugs.


jshint is great. Putting this in ~/.jshintrc makes it a lot more sane:

    {
      "browser" : true,
      "node"    : true,
      "undef"   : true,
      "eqeqeq"  : true,
      "noarg"   : true
    }


I don't get what the issue is. I run bootstrap js through the closure compiler (with minification and optimization) and it works just fine. I don't agree with the policy myself, I prefer semicolon, but I also prefer CoffeeScript. That said, if Fat wants to remove it, that is his choice, leave him alone. Update: Just read his blog posting. If Fat really wanted the minimalist approach, he'd use coffeescript and then people would bug him over that choice instead. ;-)


I don't get what the issue is either. Are we forgetting that Bootstrap is free and open source?

Nobody's forcing anyone to use Bootstrap nor is anyone prevented from creating their own Bootstrap fork with semicolons.

Clearly, no good deed goes unpunished.


Did you just say using CS is minimalist?


I believe he was referring to terse code.


I want top point out that this shows how it is very very tricky to build a good team. Just imagine that one of your co-workers (very smart, the best, but refuses to understand 'principle of least surprise') is refusing to add semicolons and claiming we now need to change mimifier and change a way how we use 3rd party js dynamic loaders. And that can cause quite unpleased dynamic in the team.

This is one of reasons why companies have strict coding-style guides but that is overhead for a very small company (you don't need coding-style you just need developers which know that code needs to be written with understanding it will also used and maintained by other people in your team).


And if your good programming team can't figure out that they might need to edit a coworker's Javascript library to add in missing semicolons in order to cleanly minify their scripts, you have a different (bigger) problem.


Not having to use semicolons sounds nice, but in practice it can have terrible effects. E.g.:

  var x = function() {
    // something
  }
  
  // avoid polluting global scope:
  (function() {
    // Some initialization.
  })()
This will call the function x with the anonymous function as its argument, and then call the result of that.

There are more examples to that point, and many of them really aren't all that straightforward. So don't rely on automatic semicolons.


First commandment of semi-colon-free: any line that starts with [,(,+,- should be prefixed with a semi-colon.

  var x = function() {
    // something
  }
  
  // avoid polluting global scope:
  ;(function() {
    // Some initialization.
  })()

  ;[1,2,3].forEach(...)
In practice those are the only places you'll see (and need) them. It has the extra benefit of disencouraging starting a line with a pre-increment, hacks or weird constructs (not talking of IIFEs of course), and making sure you're never calling a function or accessing properties by accident.


Good advice, and interesting because languages and syntax are interesting to me. But I would never introduce this in my team as a replacement for semicolons at the end of each statement. It seems too random a rule to just follow, hence you'd need to understand the specific problem that it solves. At that point your mental model has become slightly more complex, which doesn't seem worth it.


It's absolutely not random. You only put semi-colons where needed. There is no optional use.

'semicolons at the end of each statement' is much more random. They are unnecessary after function declarations or conditionals, and you might end up forgetting them somewhere that actually matters, just because you're not paying attention. The mental effort for this change is severely overestimated.


But if that really is the only rule needed, then that should be very easy to add to a linter.


You can write this without any problem:

  var x = function() {
    // something
  }

  // avoid polluting global scope:
  !function() {
    // Some initialization.
  }()


So now you've gone from a semicolon, which has the sole purpose of separating statements; to a bang, which doesn't make any sense in this context unless you know that it's replacing a semicolon.

Better or worse?


You could use anything which separates statements or ensures the function is treated as an expression. Two examples which are more in keeping with the intended use of the operators in question:

  ;function() {
    // Some initialization.
  }()

  void function() {
    // Some initialization.
  }()


So now we've gone a) from semicolon consistently after statements, to having to remember where to prefix with semicolons, or b) from one character to four.

Why aren't we just using the semicolon as it is required in any other (C-based) language?


JS's syntax is influenced by C via its pretensions of being somehow related to Java, but I think it's a stretch to call it a "C-based language".


Check out the following issue, not just the matter of style..

https://github.com/twitter/bootstrap/issues/401


> many providers (o2, t-mobile, vodafone) across the world embed another js script

> The lack of semi-colons in the dropdown js file causes this compression to break

Thanks for the heads up, no bootstrap for me! (At least without something that's going to add the necessary semicolons... I wonder how many HN weekend projects out there simply don't work for people using their wireless connections?)

Also interesting that it appears the issue was closed because it contained the key phrases 'compression' and 'semicolon'... but it was not re-opened even after the maintainer realized the problem is with the wireless providers.


The reply seems immature from the perspective of project maintenance.


That seemed to be a trend in this project, that we briefly overcame: https://github.com/twitter/bootstrap/pull/266


Agreed. Aesthetics should be the first thing to go when they cause real-life issues for what you are making. The only value of the aesthetics of not having semi-colons is to the developer himself.


Even when using semi-colons freely, most people don't put a guarding ; at the beggining or end of the file. That's unrelated to this coding style.

And honestly, that should be done by the minifier. It breaks perfectly valid javascript.


I have created a repo at git://github.com/rajivnavada/bootstrap.git that addresses this issue in the Makefile.

Basically, I added a 'proper' target that 'bootstrap' depends on. This target simply adds the semicolon to the end of the file. Hope it helps those of you having problems.


This is extremely frustrating. I have to create a special code path for Bootstrap JavaScript because it can't be minimized using the standard tooling that works on everything else.


one could argue that the toolchain sucks if it can't process valid JS


That would also be extremely frustrating if one argued that.


huh, isn't the bug rather in the software that can't deal with the "missing" semicolons? (I hate semicolons, too)


I agree with this, any minifier worth using handles semicolons just fine. Try uglify.


I avoid using the semicolon in JS because doing so forces me to be aware of the semicolon insertion rules. Forgetting them can lead you to believe that statements like

    return
    { foo: 3 };
do what you expect :)


Why would you ever write that


This has bothered me so many times when using Bootstrap. The compressor I mainly use (UglifyJS) handles the compressing alright, but the concat process fails. At least just have a semicolon at the end of all JS files and that's enough for most people.


I think this is one of those stylistic preference issues that basically doesn't matter, which is why people will probably go on about it for weeks with no resolution in sight.

Personal anecdote time: I've been writing Javascript for my job for about 16 months now. When I started, I read all the same material as the readers of this site probably did, mostly written by Crockford, advocating a certain brace/semicolon heavy style. But after dutifully following this for about 6 months, I started to notice that I had made many 'mistakes' in the code, to do with missing semis particularly, and so had a lot of other people in the company. Of course, all the code ran fine everywhere and nobody had noticed in 6 months.

So, when writing code for personal exploration at home, I stopped using semis. It's surprising how much time you spend making sure they are there when the interpreter won't check for their presence (and doesn't care either way). Issues can crop up to do with missing semis, but so far I haven't had a single issue, probably because i'm aware of avoiding certain things, like starting a line with a bracket.

So, in my personal experience, it hasn't mattered to have them or not. If you absolutely need them for minification or similar, you should be using a compiler like yui. You are going to make a mistake if your code base is large enough to matter, irrespective of how vigilant you are, so you might as well leave minutiae like this to a computer.


Along with not inserting a linebreak immediately after a return (which you must learn whether you use semicolons or not), watching out for lines starting with braces accounts for the vast majority of potential ASI errors you're likely to encounter in the wild (in fact, I don't think I've ever been bitten by ++, unary +/-, or a leading RegExp literal), so it's no wonder you didn't see any issues keeping that one, simple rule in mind.


I think this is one of those stylistic preference issues that basically doesn't matter, which is why people will probably go on about it for weeks with no resolution in sight.

In theory, yes, it doesn't matter. In practice, it does (and YUI, etc. do not fix the problem):

https://github.com/twitter/bootstrap/issues/401


I don't see how this is the original authors problem actually, regardless of the cause. Someones incorrectly written code injected into your own runtime environment could cause all sorts of weird problems.

IMO this is a reasonably serious browser security issue along the same lines as CORS, but thats another argument.


Well, this is a stylistic preference issue that does matter if it causes issues for people using certain tools or in certain situations (such as the tethering ISP issue).


Has anyone on this thread RTFS?

Semicolons are not optional. They are inserted for you as a convenience when the parser can figure out what you meant.

This situation wasn't a big deal in the early days. But the patterns of coding that have emerged to deal with Javascript's scoping problems have brought this from a curiosity to something profoundly crazy.

Using an operator (i.e. !) to fool the parser is hilarious but really not OK.

Writing code is an exercise in communication. You are communicating with other programmers (including your future self) and the parser. The zero semicolon style espoused by @fat is problematic for both other programmers and the parser. Perhaps one day @fat will win and his style of communication will be sufficiently accepted to be valid but this is not that day.

The relevant section of the ECMAScript spec is included for your convenience:

7.9 Automatic Semicolon Insertion Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations.

http://www.ecma-international.org/publications/standards/Ecm...


I don't see it as really a problem. Its just a matter of personal coding preference.

As far as minification and optimization is concerned it works fine using yui, google closure, uglify.js .

(also mentioned by fat in https://github.com/twitter/bootstrap/issues/401#issuecomment...)


http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...

A proper minifier/concatenator will add the necessary shielding semi-colons. Don't use anything that messes with your code without parsing it.


How can ideologies on such futile things as a semi-colon get in the way of playing nice with others? Just put that in perspective with RMS' intransigence in his conviction and fight for freedom. Freedom and semi-colon, which is the more fundamental and worth fighting for?


This whole thread is probably going nowhere, imo. The maintainer has valid reasons - and it's part of the spec. The issue raisers have their reasons - minifiers don't work for them. Here's the beauty of git and github, one can always run a fork :)


Really formatting wars are really stupid. ASI is like indentation, it is trivial to write a program that converts between the two representations. The last time we had an issue about this at work, someone just wrote a pre-commit hook that sets the indentation to be standard without changing the parse tree (it actually asserts the parse tree is the same).

Now you can code any way you want, but no more white-space changes cluttering up the history of files. This is the worst type of holy war because it not only doesn't matter much (which is true of any) but there is a technological solution that the engineers involved are all ignoring.


It's amazing (and funny) how this whole semi-colon thing is based on fear.

People should understand the role of semi-colons and ASI, just like they should understand the comma operator. It's not hard, takes 10 minutes (read Isaac's post).

Everyone saying that they don't need to understand it is doing a disservice to the community, there's no harm in wanting knowledge of the language to evolve. A few years back people seldomly used IIFEs, and I remember hearing the same argument (wtf is that, don't use it, I don't understand). Change is good.


There's no should about it. I know ASI exists, and I also know I need never concern myself with it, because I prefer the simplicity and consistency of finishing each line with a semi-colon.


Is this really about semicolons, or is it just that with so many fucking people watching, using, and messing around with the bootstrap repo that you're bound to find a bunch of bizarre little edge-case problems? You know what I mean?

My repos don't have a lot of semicolon-related problems, because they don't have almost 20,000 watchers and tons of people using my code.


Thanks for drawing my attention to this.

Am I the only one who now won't consider using Bootstrap for a project (based on this semicolon issue)?


Yes.

Or at least, I would still use bootstrap even if I had to throw out all of the js.


One cold dark night in Javascript-land...

A: Hey, remember when coding was fun? When it was an extension of yourself and you got to create things with it? Create things!

B: No. We're not allowed to do anything except what the Good Book deems acceptable.

A: But, but, you get to take this blank slate and carve out of it whatever you can imagine! Pure expression! And remember when you prioritized your coding style for enjoyment?

B: No. Coding is not fun. Coding is about maximum compliance.

A: ... I remember, but sometimes I think the web has forgotten.

A: I mean think about it. We're banished from the 'new' keyword. We can hardly use polyfills or even extend the native prototypes. How I used to love statements like [[1,2],2,3].flatten(), but lo they are forbidden! Having even one prototype extension in your library is a death sentence. No having fun in Javascript-land!

B: True, fun is not allowed.

A: Hey, what's that over there? That gleaming light coming from the back of that house? Is that a party? Hey it's that house that @fat and @mdo built. They're having fun? We should join them!

B: You don't want to go there man. They don't use semicolons.

A: Is that all they're doing? So what, they're not following the Good Book? They're not afraid to do things a bit out of the ordinary? I'm out of here. See you later Javascript-land. B, I'm going to have some fun with those guys.

B: ... prototype extensions?

(Thanks @fat, @mdo & Twitter for Bootstrap, and for giving it away nonetheless. If I ever have a problem minifying your code, I'll fork it and just add the semicolons myself.)


Stupid question maybe but what's wrong with the included bootstrap.min.js? What am I missing?


Basically, people don't want the minified versions of files while they're developing, and there will always be people coming to the project with whatever minification tools in their build that can't handle the missing semicolons. Currently, the answer is "change your build tools".

https://github.com/twitter/bootstrap/issues/1795


When things break (and they do) having a stack trace start in the bowels of a minified library is hell. So you'd generally use the "normal" library and the project's minification/concatenation tools.

Even when they handle ASI itself correctly, these tools don't always handle things that nicely across files.


I don't think this is a matter of taste. I think this is showing off for the sake of it.


This sounds a lot like the spaces vs tabs holy war. The C way vs the Ruby/Python way.


I also hate it. And the colon, for that matter.


That's a reasonable thing to hate.


problem here is ruby.ruby developers hate semicolons. They ignore the decades old history opf the semicolon, and assert that the ruby/python/haskell way of indentation and semicolon-less code is the better way. They COULD be right, but im too deep seated in C/C++/Java/JS. One of the problems with javascript is the fact that it gives the choice.


Actually, it has nothing to do with ruby. The problem here is that some people use minification tools that rely on semicolons. If that weren't the case, this would be a total non-issue.


Agreed.

The first language I learned was VB6 (ewww), after that C, C++, Java, JavaScript and PHP, only a few years ago I started to hear a lot about Python, Ruby, etc.

I don't see what's the problem with the braces and semicolons, I got used to write them and I don't see it affect my coding speed or code readability, in fact I find it easier to read code with braces and semicolons, I learned a little of python a few months ago and ignoring the fact that I do not know the language syntax very well (or more common libraries) yet, I write it as quickly as I would write Java/C etc, for readability I read python slower but as I said I'm not used to the syntax/libraries/etc yet so that may be the problem.


Actually, Haskell lets you do it either way. It's the best of both worlds :)

This code:

    do a <- [1,2,3]
       b <- [4,5,6]
       return $ a + b
can also be written as:

     do {
       a <- [1,2,3];
       b <- [4,5,6];
       return $ a + b
     }
or:

     do { a <- [1,2,3]; b <- [4,5,6]; return $ a + b; }
I've even seen it like this:

     do { a <- [1,2,3]
        ; b <- [4,5,6]
        ; return $ a + b }


JavaScript also permits you do it either way. That's what this whole argument is about!


I'm merely responding to the parent's "ruby/python/haskell way of indentation" phrase.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: