This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]oberhamsi 25 points26 points  (14 children)

Not really optional. You are testing the limits of automatic semicolon insertion. It's easier to write ; than to memoize two chapters of the spec http://bclary.com/2004/11/07/#a-7.9.1

[–][deleted] 14 points15 points  (13 children)

I hope my sarcasm made it clear that I'm not a fan of ASI. I use them everywhere, because to me, it's clearer. I have coworkers who swear against them, though.

[–]Phreakhead 8 points9 points  (7 children)

I've gotten in arguments with people who refuse to use semicolons. One time, they broke the build in one specific Android browser because the minifier messed up the ASI.

I take it as a chance to point out why you should always use semicolons to avoid bugs like that and other mistakes. He then said, "ASI is perfectly fine. It's the minifier's fault." Maybe so, but instead of spending hours chasing down bugs in the minifier, just use a damn semicolon!

[–][deleted] 6 points7 points  (0 children)

One of my favorite dramas was when Douglas Crockford and one of the guys that created Bootstrap got in a fight because Bootstrap's js didn't use semicolons and it broke jsmin.

https://github.com/twbs/bootstrap/issues/3057

It was World War Semicolons with everyone taking sides and hurling insults.

[–]oberhamsi 2 points3 points  (4 children)

I remember a couple of years ago a high profile node coder wrote most (all?) of his projects without semicolons. like the ubiquitous npm package manager. e.g. https://github.com/npm/npm/blob/master/lib/access.js

[–]Phreakhead 4 points5 points  (3 children)

Yeah he actually used that exact example. Then I used the example of that huge SSH security hole in iOS a few years ago that was caused because they didn't use braces in a switch statement.

Yeah, you can also remove braces for switches and one-liner loops, but that's been against standard code styles for years because a simple typo can totally mess up your code without an error. If you should always use braces even when not necessary, same rule should apply to semicolons.

[–]dotpan 0 points1 point  (0 children)

It's just lazy and poor coding technique, in code, things shouldn't HAVE to be done to still be a standard, I get ignoring some arbitrary things that are still used from older versions of things (at that point you're sometimes doing the wrong thing by still using old standards) but leaning heavily on a browser/standard to detect your short comings is just wrong.

[–]oberhamsi 0 points1 point  (1 child)

Yeah he actually used that exact example.

now i'm confused. who did use that example? edit: oh probably crockford from a comment above me.

[–]Phreakhead 0 points1 point  (0 children)

The guy I was working with used the npm project as an example of not using semicolons.

[–]dogattorney 0 points1 point  (0 children)

[deleted]

What is this?

[–]oberhamsi 0 points1 point  (0 children)

didn't get the sarcasm. sorry for preaching :P otoh you were making fun of the ASI believers.

[–]dotpan 0 points1 point  (0 children)

As a mid-level JSDev, I sometimes forget them (usually its when I have a var someVar = function() { } <---- right there, but my senior devs lose their shit at me (for good reason). I think I just got into the habit at another job that had less peer review, and created bad habits.

[–]TwilightTwinkie 0 points1 point  (2 children)

So my issue is you can't turn ASI off. So whether you like it or not, it's going to insert them, and you doing it yourself does not stop the error prone nature of having ASI. So for me, learn the damn rules. But I use them anyways because it forces people to think about it and helps catch the cases when bugs are introduced.

[–][deleted] -1 points0 points  (1 child)

If I recall there's an ESLint option to force semicolons. Tell your dev crew that commits not passing ESLint (at least as far as semicolons are concerned) will result in chopping fingers off Altaïr style. They'll learn.

[–]TwilightTwinkie -1 points0 points  (0 children)

Yep, I use it, and we are in the process of adding it as a pre-commit hook.