5 ms·
There was some debate at an old job about whether or not to use semicolons in JavaScript. I would just like to remind everyone reading this that if you don't wr
by ddevault 7y ago
There was some debate at an old job about whether or not to use semicolons in JavaScript. I would just like to remind everyone reading this that if you don't write semicolons in your JavaScript, you are doing it wrong, and we cannot be friends.
- jakear 7y agoI’ve said it before, I’ll say it again. Semicolon-free JS is much easier to edit, and the typical foot-guns associated with it can be trivially avoided with a formatter/linter.
- tylorr 7y agoSemicolons can also be automated, which is what I currently do at work.
- jakear 7y agoSee reply to sibling. It’s not about inserting the semi, that’s trivial.
- SPBS 7y agoSemicolon JavaScript is trivially easy to write with a formatter -- just hit format and it inserts semicolons for you. And has no footguns.
- jakear 7y agoIt’s not writing the semis themselves that’s the issue - obviously that’s trivial. It’s editing lines that have semis. Any “to end of line” operation (and there are tons) you have to think about whether you want the semi or not, which often depends on what the future context will be. This is one of those things where once you get used to “power-editing” in semi-free, it’s very difficult to go back. And note that the bulk of my work is semi-d, I only go semi-free on greenfield projects. So it’s not a case of having more experience one way or the other. Any lisper/schemester will tell you that reducing syntax makes power editing simple, but for some reason JS people love their semi’s. Beats me.
- throw_m239339 7y ago> There was some debate at an old job about whether or not to use semicolons in JavaScript. I would just like to remind everyone reading this that if you don't write semicolons in your JavaScript, you are doing it wrong, and we cannot be friends. Well the great thing with that issue is that you can use tools that will forcefully put semi-colons in code and no rely on automatic insertion at runtime. There is no excuse today not to do that. Of course, sticking to a specific coding style and enforcing it automatically with QA tools during CI is also something easy to do and should be mandatory for any codebase.