Bootstrap's maintainer hates the semicolon
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 :)
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.
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:
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.
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 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).
Not having to use semicolons sounds nice, but in practice it can have terrible effects. E.g.:
This will call the function x with the anonymous function as its argument, and then call the result of that.var x = function() { // something } // avoid polluting global scope: (function() { // Some initialization. })()
There are more examples to that point, and many of them really aren't all that straightforward. So don't rely on automatic semicolons.
Check out the following issue, not just the matter of style..
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.
huh, isn't the bug rather in the software that can't deal with the "missing" semicolons? (I hate semicolons, too)
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
do what you expect :)return { foo: 3 };
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.
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.
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)?
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.)
undefined
Stupid question maybe but what's wrong with the included bootstrap.min.js? What am I missing?
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.
My assembler uses my C Lex() which mostly ignores carriage_return. My asm instructions can be split on multiple lines. My define byte requires a terminating semicolon.
I once had a silly instructor who decided to show-off by not requiring a ; before asm comments on lines, and made a special editor that distributed comments into paragraphs along-side code. That's just stupid. What if you want a tool to process code -- you just increased the difficulty of parsing.
My assembler requires different opcode numonics for instuctions with 1 vs 2 args.
God says... C:\LoseThos\www.losethos.com\text\YANKEE.TXT
d not hesitate this time. The moment we were in the road I ran; and after a moment he threw dignity aside and followed. I did not want to think of what was happening in the hut--I couldn't bear it; I wanted to drive it out of my mind; so I struck into the first subject that lay under that one in my mind:
"I have had the disease those people died of, and so have nothing to fear; but if you have not had it also--"
He broke in upon me to say he was in trouble, and it was his conscience that was t
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.