12 ms·
Bootstrap's maintainer hates the semicolon
- jondot 15y agoThat's a reasonable thing to hate.
- nestlequ1k 15y agoIf 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.
- lloeki 15y agoFor the sake of completeness, PEP8 actually says 'Use 4 spaces per indentation level'
- mrspeaker 15y agoHe'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 ;)
- VMG 15y agoalternatively, use JSLint
- beaumartinez 15y agoI 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 15y agoThere 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.
- bronson 15y agojshint is great. Putting this in ~/.jshintrc makes it a lot more sane: { "browser" : true, "node" : true, "undef" : true, "eqeqeq" : true, "noarg" : true }
- Rajiv_N 15y agoThanks 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 :)
- willvarfar 15y agoYour branch can become the new public useful one perhaps?
- Rajiv_N 15y agoYeah, 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 https://github.com/rajivnavada/bootstrap
- oscardelben 15y agoYou can do it in Ruby and lots of other languages
- TomasSedovic 15y agoRuby, Python, Go, JavaScript, Bash, even Clojure -- kinda. https://gist.github.com/1815639 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.
- mjwalshe 15y ago
- latchkey 15y agoI 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 15y agoDid you just say using CS is minimalist?
- danneu 15y agoI believe he was referring to terse code.
- slantyyz 15y agoI 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.
- Tichy 15y agohuh, isn't the bug rather in the software that can't deal with the "missing" semicolons? (I hate semicolons, too)
- secoif 15y agoI agree with this, any minifier worth using handles semicolons just fine. Try uglify.
- evan_ 15y agoHe 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/ http://www.wordsbyf.at/2011/10/31/i-dont-write-javascript/
- damncabbage 15y agoAnd possibly some reasons why leaving semicolons off can make his or others' lives a bit annoying: http://bonsaiden.github.com/JavaScript-Garden/#core.semicolon http://bonsaiden.github.com/JavaScript-Garden/#core.semicolo...
- ricardobeat 15y agoThat'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...
- damncabbage 15y agoHow 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()
- idan 15y agoThis 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.
- deleted 15y ago[deleted]
- evilvoidhamster 15y agoproblem 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 15y agoActually, 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 }
- LoneWolf 15y agoAgreed. 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.
- losethos 15y agoMy 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
- etfb 15y agoIdealism 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.
- raphinou 15y agoHow 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?
- Rajiv_N 15y agoI 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 15y agoThis 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.
- tszming 15y agoCheck out the following issue, not just the matter of style.. https://github.com/twitter/bootstrap/issues/401 https://github.com/twitter/bootstrap/issues/401
- matt_yoho 15y agoThe reply seems immature from the perspective of project maintenance.
- brown9-2 15y agoAgreed. 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.
- glenngillen 15y agoThat seemed to be a trend in this project, that we briefly overcame: https://github.com/twitter/bootstrap/pull/266 https://github.com/twitter/bootstrap/pull/266
- jed_s 15y ago> 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.
- ricardobeat 15y agoEven 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.
- kuahyeow 15y agoThis 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 :)
- theone 15y agoI 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-2348795 https://github.com/twitter/bootstrap/issues/401#issuecomment...)
- josephcooney 15y agoI don't think this is a matter of taste. I think this is showing off for the sake of it.
- nornagon 15y agoI 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 15y agoWhy would you ever write that
- JackdawX 15y agoI 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.
- insin 15y agoAlong 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.
- brown9-2 15y agoWell, 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).
- eropple 15y agoI 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 https://github.com/twitter/bootstrap/issues/401
- Kiro 15y agoStupid question maybe but what's wrong with the included bootstrap.min.js? What am I missing?
- jed_s 15y agoBasically, 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 https://github.com/twitter/bootstrap/issues/1795
- masklinn 15y agoWhen 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.
- sylvanaar 15y agoThis sounds a lot like the spaces vs tabs holy war. The C way vs the Ruby/Python way.
- sjwright 15y agoI 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 15y agoIt'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 15y agoAnd is therefore more expensive to maintain.
- ypcx 15y agoIt'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 15y agoI 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.
- angelortega 15y agoI also hate it. And the colon, for that matter.
- beggi 15y agoThis 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.
- ricardobeat 15y agohttp://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding 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.
- rudiger 15y agoThanks 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 15y agoYes. Or at least, I would still use bootstrap even if I had to throw out all of the js.
- Nitramp 15y agoNot 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.
- Calvein 15y agoYou can write this without any problem: var x = function() { // something } // avoid polluting global scope: !function() { // Some initialization. }()
- evan_ 15y agoSo 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?
- insin 15y agoYou 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. }()
- mkopinsky 15y agoSo 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?
- 15y ago
- ggwicz 15y agoIs 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.
- tlogan 15y agoI 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 15y agoAnd 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.
- ricardobeat 15y agoIt'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 15y agoThere'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.
- aidenn0 15y agoReally 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.
- n8agrin 15y agoOne 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.)
- michaelw 15y agoHas 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/Ecma-262.htm http://www.ecma-international.org/publications/standards/Ecm...