bevacqua / js

:art: A JavaScript Quality Guide
https://ponyfoo.com
MIT License
2.92k stars 497 forks source link

ASI #18

Closed NadyaNayme closed 9 years ago

NadyaNayme commented 9 years ago

Automatic Semicolon Insertion (ASI) is not a feature. Don't rely on it. It's super complicated and there's no practical reason to burden all of the developers in a team for not possessing the frivolous knowledge of how ASI works. Avoid headaches, avoid ASI.

Always add semicolons where needed

To quote standard out of laziness:

No semicolonsIt's fine. Really!

There is only a single rule that is a real "gotcha!" and memorizing a single rule is not "frivolous knowledge of ASI".

I'm impartial about whether to avoid or use semicolons. However spreading FUD as the reason to use them should not be how a responsible developer does it. It's largely a stylistic issue. Feel free to advocate for the use of semi-colons but please make sure you aren't doing so under false reasons.

Regardless, I'd take a programmer with frivolous knowledge of how a language actually parses and functions over one who doesn't any day of the week.

Relevant to above statement: http://www.slideshare.net/olvemaudal/deep-c

bevacqua commented 9 years ago

Well. Knowing to use ; before ( and [ if they come after a \n, and not to do return\nvalue is not necessarily something to be proud of. I'd rather have code be consistent (just using ; everywhere), than having to bother following those rules.

Not really FUD, the rules are obtuse. The solution proposed by standard, where the linter watches for these corner cases and tells you to patch them is pretty elegant, though. You're welcome to create a pull request citing this alternative

NadyaNayme commented 9 years ago

That's a rather over-complicated way of saying "never start a line with ( or [ "... The specifics aren't overly important in that regard as the simple and easy to remember rule would prevent the specific "gotchas!" although the specifics are still good to know to better your understanding of the Javascript parser.

Code would be consistent with or without ; as long as it picked one style and stuck with it. ;)

Again, I don't care which people decide to use. So long as the code base is consistent. I actually prefer using ; , however my reasoning to do so is aesthetic in purpose rather than being based on FUD (we're going to have to agree to disagree on the information surrounding ASI being FUD or not it seems)

I'll submit a PR as suggested sometime tomorrow that proposes using a linter to watch for the "gotcha!" as an easy-fix to any possible ASI issues of not using semi-colons.