7 ms·
Heh, I was waiting for this post. Coming in the next 24 hours: - "Why I use minimal semi-colons in Javascript" - "ASI is broken but I like it" Honestly I'm s
by cletus 15y ago
Heh, I was waiting for this post. Coming in the next 24 hours:
- "Why I use minimal semi-colons in Javascript"
- "ASI is broken but I like it"
Honestly I'm shocked at the defense of this practice (of ASI "abusage"). It speaks loudly to Jacob's (fat@githib) ranking of ego-stroking and showboating over creating readable code, particularly for a library "Designed for everyone, everywhere" [1].
I'm confounded that such an attitude can survive in a large engineering organization like Twitter. Google's style guide [2] specifically prohibits this ("Always use semicolons.") and yes, this is the same standard we use internally for writing Javascript.
Just because you can doesn't mean you should. FFS, just get over yourselves and your hipster bullshit and use semi-colons.
[1]: http://twitter.github.com/bootstrap/ http://twitter.github.com/bootstrap/
[2]: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Semicolons http://google-styleguide.googlecode.com/svn/trunk/javascript...
- dlitz 15y ago> I'm confounded that such an attitude can survive in a large engineering organization like Twitter. I'm not surprised. A bit disappointed, but not surprised. Have a look at the original OAuth specification sometime. Note how they misuse the word "key" to mean "identifier". I can't imagine that anyone writing a crypto specification wouldn't know that this would be confusing; I think it's more likely that the person just didn't care. Also, there's the fact that the whole thing could have been written as just a way of getting Basic authentication credentials, rather than making up a whole new authentication scheme. And then there's the hashbang thing...
- Terretta 15y ago> then there's the hashbang thing Thank you. I agree both of these show a casual disregard for "how the real world works", where not everyone is a "rock star", some are lowest common denominators using the web as best they can (and good for them for even trying!), and some just need to get things done. Every extra exception you require in a user's mind makes your work and the web in general just that little bit less accessible. That it is being done for "style" in an arena of notoriously unsophisticated users, really feels like a giant middle finger. Kudos to Google for their style guide freeing up this particular "exceptions" pigeonhole from a JS programmer's mind, so she can use the synapse to get something done instead. // Using JS in the real world since Netscape 2.0.
- jbrkr 15y agoLet's not forget... Twitter may have made the hashbang infamous, but it was originally championed by Google [1]. [1]: http://googlewebmastercentral.blogspot.com/2009/10/proposal-for-making-ajax-crawlable.html http://googlewebmastercentral.blogspot.com/2009/10/proposal-...
- Terretta 15y agoPage state and uniform resource location, I feel, are utterly different. Hash bang shouldn't be which user's tweets we're looking at, or which article on Gawker. Google's examples show the hash bang after the query. Twitter put the query after the hash bang.
- Natsu 15y agoI'm surprised no one has made a little command line tool that follows the rules and automatically inserts semicolons according to the ASI spec. That might even be useful.
- OzzyB 15y ago...or perhaps a simple "Zen of Javascript" would be in order. Reading this "debate" makes me thankful for the Python Community and their stance on "readable code" above all else.
- andrewflnr 15y agoNow that you mention it, every language should have a "Zen" statement, or if you don't want to call it that, a short description of its philosophy. This in addition to the concise problem/solution statement that probably every piece of software should have.
- aubergene 15y agoClosure linter's fixjsstyle can do this https://developers.google.com/closure/utilities/ https://developers.google.com/closure/utilities/
- tree_of_item 15y agoI really don't understand how a particular usage of semicolons and logical operators is indicative of ego-stroking, showboating, and "hipster", as if the word hipster even means anything at all. If fat _said_ something to make you use those words then that would make sense, but as it is I'm very confused.
- alanh 15y agoSimple. Look at the other comments, and it becomes apparent there are downsides to relying on / abusing ASI, and no advantages. (The only claimed advantage is that the lack of semicolons is visually appealing, but this is nullified by the fact the rules are sort of confusing and not apparent to all contributors.) Thus people are inferring this fat fellow is doing it only out of illogical, ego-based personal preference, because nothing else makes sense. I’m not saying they are right — I couldn’t possibly know — but given the facts, it’s a reasonable assumption.
- ricardobeat 15y agoFIY the main claim is that it's a more reliable way to write js: programmer mistakes/missing semi-colons are more easily noticed, and much less common, since the rules are simpler. It's there in every debate about this.
- alanh 15y agoI’m sorry, but I don’t know what “FIY” means, what your point is, or how your comment is a reply to mine. Consider re-phrasing?
- ricardobeat 15y agoI misspelled FYI - "for your information". You said there are only downsides, and no advantages; I just told you what the claimed advantage is for "abusing" ASI. I hope you're not just being snarky.
- 15y ago
- web_chops 15y agoThat is what surprised me a lot. That there would be so much defense of the practice. I work on C/C++ for a living in enterprise environment and there are style rules followed diligently. Every one knows that there can be lot of cool/hipster code written with C/C++ but no one does because of the maintenance concerns. Writing code is much easier than maintaining it.
- chad_walters 15y agoWhat are the universally accepted style rules for C/C++? Every organization I have worked in has had to develop their own guidelines around style in C/C++. What really surprises me is that such a large number of people are quick to attack someone for writing legal code simply because they disagree with the style used. It feels awfully close to attacking someone for using a different bracing style from your preferred bracing style.
- jcoffey 15y agoThe feature in question is intended as an error correction for those cases where the programmer accidentally left out newline. A misguided feature maybe, but it's clearly being abused by intentionally leaving out every (or most) newlines.
- regularfry 15y ago> What are the universally accepted style rules for C/C++? Whenever I've been asked this, I've pointed people at the JSF-AV coding standards or MISRA. > What really surprises me is that such a large number of people are quick to attack someone for writing legal code simply because they disagree with the style used. The important part of the lifecycle of a piece of code isn't the writing of it. It's the maintaining and rewriting that matters. If one coding style makes it easier to introduce errors than an alternative, that's a bad thing. It's not an aesthetic concern. Semicolon-less JS is demonstrably less robust.
- nhebb 15y agoThe GitHub style guide recommends the opposite: "Do your best to never use a semicolon. This means avoiding them at line breaks and avoiding multi-statement lines. For more info, read Mislav's blog post [2]." FWIW, I agree with the Google style guide. Maybe I'm interpreting it wrong, but ASI struck me as a fail-safe to protect coders that forgot the occasional semicolon and was later mis-identified as a feature. Having Brendan Eich weigh in on this is akin to having Thomas Jefferson pop his head into the Ninth Circuit and clarify an issue over Constitutional intent. If it were me, I'd listen to Thomas Jefferson. [1] https://github.com/styleguide/javascript https://github.com/styleguide/javascript [2] http://mislav.uniqpath.com/2010/05/semicolons/ http://mislav.uniqpath.com/2010/05/semicolons/
- tzs 15y agoThat blog post they cite includes this: My advice on JSLint: don’t use it. Why would you use it? If you believed that it helps you have less bugs in your code, here’s a newsflash; only people can detect and solve software bugs, not tools. So instead of tools, get more people to look at your code. Unless I'm missing something, that easily qualifies as the dumbest thing I've read on the net in the last week--and I've been to /r/politics.
- maw 15y agoYou're not missing anything. It's dumb. JSLint doesn't find all the bugs in my code, but it does find quite a few. There are several places where I deliberately ignore its recommendations, but all in all I take what it says seriously. I'm sure you do likewise.
- brown9-2 15y agoI find it odd that they (Github) don't really bother to justify their stance on this. The guide just says "don't use them", not why they find it in their interest to do so. It'd be interesting to get a better understanding of why they think this. Personally I don't see the point in omitting something that leads to known problems instead of including it and encountering zero problems.
- Lewisham 15y agoWhat surprises me is not that Fat is a bit of a jerk (note, I "get" it, but I don't respect it), but that Twitter lets him keep being a jerk and actively hostile while acting as a representative of the company. If he wrote Bootstrap by himself, he's free to call every single user an idiot if he wishes, but when it's being released as a Twitter product, one would think Twitter would demand some modicum of respect to be shown. Can you imagine a Googler acting this way on the Chromium or Android projects? Yeah, there are decisions made on those where people aren't happy, but the comments aren't laden with zingers either. If Douglas Crockford comes down and tells me I'm doing JavaScript wrong, I would hope I'd show a bit more respect to someone who's most likely my better.
- jrockway 15y agoWhat surprises me is not that Fat is a bit of a jerk (note, I "get" it, but I don't respect it), but that Twitter lets him keep being a jerk and actively hostile while acting as a representative of the company. My observation of open-source community dynamics tells me that being hostile is an effective way to lead a large community. I've noticed that contributors act more carefully around someone who is mean to people in general and that these people attract wide followings at conferences. (There are certainly exceptions, though, like Larry Wall.) Can you imagine a Googler acting this way on the Chromium or Android projects? Being nice also works, but if you compare Chrome's reach to this Javascript framework's reach and use that to scale the number of contributors, you'd expect a lot more contributions to Chrome. I think fat is a jackass, but if he wasn't, I never would have heard about this project, which now has multiple front page articles on multiple tech sites. I imagine this is good for Twitter.
- gbog 15y ago> being hostile is an effective way to lead a large community. No, those are the exceptions. Being opinionated and ready to say no, however, is necessary.
- vorg 15y agoThen there's the open source project "leaders" who're nice and smiley to people publicly, but snide and nasty through anonymous backchannels.
- tzs 15y ago> Honestly I'm shocked at the defense of this practice (of ASI "abusage") Devil's advocate here: could one argue that taking advantage of ASI everywhere can make it safer, because it forces you to be fully aware of ASI? Suppose you always put in semicolons. You can STILL get bitten by ASI. The classic example is return { ...stuff... }; ASI is going to put a semicolon right after the return and break your code. Someone who strives to take advantage of ASI everywhere they can is going to remember that ASI is going to apply on that return, and they will code the above so as to take it into account.
- ahoge 15y agoThere will be no issues if you follow JSLint's/Crockford's suggestions. Furthermore, it simplifies the language drastically. I really don't want to deal with this kind of stuff: https://github.com/twitter/bootstrap/issues/3057#issuecomment-5140311 https://github.com/twitter/bootstrap/issues/3057#issuecommen... (Just like I don't want to deal with those massive ==/!= tables.)
- Michiel 15y agoI am currently writing the a style guide (for a small agency), and I have added semi-colons as preferred for JavaScript. And abusing the && operator like in the now infamous code snippet is definitely out. Our code needs to be maintainable for inexperienced developers. I don't want to make it easier for them to make mistakes and I don't want them to ponder rare (though valid) syntax. I feel this is a valid reason to maintain this rule. // This we can all understand clearMenus(); if(isActive) { $parent.toggleClass('open'); } Once a developer understands ASI and other details he is free to feel elated with his new-found knowledge, but I'd prefer if he choses to know rather than to apply these powers.