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 wh…
Bootstrap's maintainer hates the semicolon
121–130 of 137 posts
Re: Bootstrap's maintainer hates the semicolon
#122A: 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.)
Re: Bootstrap's maintainer hates the semicolon
#123Earlier quoted context omitted.
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.
Re: Bootstrap's maintainer hates the semicolon
#124I 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.
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.
Re: Bootstrap's maintainer hates the semicolon
#125Semicolons 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...
Re: Bootstrap's maintainer hates the semicolon
#126Earlier quoted context omitted.
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 (n…
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.
Re: Bootstrap's maintainer hates the semicolon
#127Earlier quoted context omitted.
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?
Re: Bootstrap's maintainer hates the semicolon
#128Earlier quoted context omitted.
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, an…
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: pri…
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.)
Re: Bootstrap's maintainer hates the semicolon
#129Earlier quoted context omitted.
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: pri…
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 bracke…
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).
Re: Bootstrap's maintainer hates the semicolon
#130Earlier quoted context omitted.
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.
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 somewh…