
Bootstrap's maintainer hates the semicolon - wyuenho
https://github.com/twitter/bootstrap/issues/search?q=semicolon
======
Rajiv_N
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 :)

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

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

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

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

~~~
rhizome
And is therefore more expensive to maintain.

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

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

~~~
loup-vaillant
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...](http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-
indentation-for.html)

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

~~~
loup-vaillant
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).

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

------
evan_
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/>

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

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

~~~
scooty-puff
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.

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

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

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

~~~
VMG
alternatively, use JSLint

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

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

------
latchkey
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. ;-)

~~~
dasil003
Did you just say using CS is minimalist?

~~~
danneu
I believe he was referring to terse code.

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

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

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

~~~
ricardobeat
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_.

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

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

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

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

~~~
matt_yoho
The reply seems immature from the perspective of project maintenance.

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

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

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

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

~~~
ericflo
That would also be extremely frustrating if one argued that.

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

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

------
nornagon
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 :)

~~~
mcantor
Why would you ever write that

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

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

~~~
eropple
_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>

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

------
michaelw
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...](http://www.ecma-
international.org/publications/standards/Ecma-262.htm)

------
theone
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...](https://github.com/twitter/bootstrap/issues/401#issuecomment-2348795))

------
ricardobeat
[http://blog.izs.me/post/2353458699/an-open-letter-to-
javascr...](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-
leaders-regarding)

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

------
raphinou
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?

------
kuahyeow
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 :)

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

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

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

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

------
rudiger
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)?

~~~
phillmv
Yes.

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

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

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

~~~
jed_s
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>

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

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

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

------
jondot
That's a reasonable thing to hate.

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

~~~
tikhonj
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 }

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

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

