It's too bad there isn't a less ambiguous way to write programming language expressions with, say, prefix notation, using a single set of characters (open and close parens maybe?) to describe the tree, etc..., and getting rid of semicolons and curly braces altogether.
Over the years I've submitted pull requests to 3 different projects that consist of a single semicolon in a semicolon-free codebase. They can be sneaky bugs to catch!
I think abusing ASI is a funny hack (and I did it for a while) but the more functional my programming style became the more ran into these cases, so I channeled my inner Douglas Crockford and reopened my bag of semicolons.
Semicolons are usually optional in JS. The 'usually' part if why it's a good idea to enforce usage of them to avoid situations like this.
You don't even need to do IEEs for this - running a function on an inline-declared array has a high probability of creeping the array up as an index on the previous expression.
I think what's more confusing than ASI are the mental gymnastics developers go through to justify typing semicolons daily, rather than installing a linter once, or reading the ASI spec.
Python and Ruby support semicolons for occasional statement termination; why is JavaScript any different? I can't help but think "semicolons by default" would be regarded as ritualistic if the practice was never popularized in the first place.
Does pressing a key on the home row really require a lot of justification? A project doesn't care how effective my tooling is if the next person doesn't have it.
I'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.
I ran into this in the pre-webpack era where it was somewhat common to just concatenate JS together in a gulp build step. We imported code from two NPM modules, and each one was wrapped in an IFEE, but the first one didn't terminate with a semicolon. Not fun to debug.
I refuse to use semi-colons in TS/JS, unless that conflicts with existing code standards. I feel like it's as if I'm using semi-colons in Go. This can easily be avoided by writing clearer code.
My problem with semi-colons is that when you force semicolons in a tslint config, applying an autoformat on a malformed input (forgetting a closing curly brace, for instance) will introduce a bunch of erroneous semicolons throughout the file, giving you a ton of syntax errors to clean up. If you’re lucky you’ll be able to undo before you continue, but I sometimes don’t notice until I’ve done a bunch of other work
Ditto. I didn't know it was a missing semicolon, but the code smells bad regardless and my solution also would have solved it another way (just by improving code readability/clarity).
It is likely one of these "trust your gut" situations.
[+] [-] slyrus|7 years ago|reply
[+] [-] Jim_Heckler|7 years ago|reply
[+] [-] scandox|7 years ago|reply
[+] [-] adrianhel|7 years ago|reply
[+] [-] ng12|7 years ago|reply
[+] [-] mrspeaker|7 years ago|reply
I think abusing ASI is a funny hack (and I did it for a while) but the more functional my programming style became the more ran into these cases, so I channeled my inner Douglas Crockford and reopened my bag of semicolons.
[+] [-] adrianhel|7 years ago|reply
[+] [-] Etheryte|7 years ago|reply
There are a number of cases where not having semicolons has its downsides, I'm yet to see a single case of an upside.
[+] [-] beering|7 years ago|reply
It's a signal of coolness from inexperienced programmers. That's the value proposition offered by semicolon-free JS.
[+] [-] Legogris|7 years ago|reply
[+] [-] adrianhel|7 years ago|reply
No. It either does or it doesn't. The spec is not ambigous.
Learn how ASI works, or you will run into trouble no matter if you prefer semis or not.
[+] [-] czr|7 years ago|reply
I'm not sure I understand why it's wrapped in an enclosing function, though; you can reproduce the error with just:
[+] [-] tastyfreeze|7 years ago|reply
Thats like neglecting punctuation in English You can but the punctuation makes it much easier to read
[+] [-] programmarchy|7 years ago|reply
A better analogy might be the Oxford comma.
[+] [-] jbredeche|7 years ago|reply
[+] [-] TeffenEllis|7 years ago|reply
Python and Ruby support semicolons for occasional statement termination; why is JavaScript any different? I can't help but think "semicolons by default" would be regarded as ritualistic if the practice was never popularized in the first place.
[+] [-] kurtisc|7 years ago|reply
[+] [-] adrianhel|7 years ago|reply
I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.
[+] [-] ezekg|7 years ago|reply
[+] [-] marshall313|7 years ago|reply
[+] [-] adrianhel|7 years ago|reply
[+] [-] telekid|7 years ago|reply
[+] [-] ezekg|7 years ago|reply
[+] [-] ezekg|7 years ago|reply
[+] [-] jakear|7 years ago|reply
[+] [-] kowdermeister|7 years ago|reply
[+] [-] jyriand|7 years ago|reply
[+] [-] tniemi|7 years ago|reply
With dangling balls: `(function(){})()`
No dangling balls: `(function(){}())`
https://gist.github.com/newswim/4668aef8a1f1bc0dabe8
[+] [-] mikewhy|7 years ago|reply
[+] [-] kgwxd|7 years ago|reply
[+] [-] gammateam|7 years ago|reply
There were obvious errors in my mind that I would fix without knowing the whole dissertation on why it happened.
So maybe if the question was, "Can you repair this code", I would excel.
[+] [-] Someone1234|7 years ago|reply
It is likely one of these "trust your gut" situations.
[+] [-] notafrog|7 years ago|reply
[deleted]