7 ms·
> cannot imagine going back to semicolons Actually, Javascript does not require semicolons to be present. If you skip them, the only edge-case is when you try
by methyl 9y ago
> cannot imagine going back to semicolons
Actually, Javascript does not require semicolons to be present. If you skip them, the only edge-case is when you try to start your line with `[` or `(`. In that case, you can prefix the line with `;`.
- ralmidani 9y agoI like consistency. And I am paranoid. When I write JS, I always include semicolons. When I write CS, it is a non-issue.
- akvadrako 9y agoI consistently don't use semicolons in JS. It's just noise.
- jdmichal 9y agoOmitting semicolons breaks the "delete a line in isolation" rule, unless you begin the line with a semicolon instead. Which is even noiser than just having them at the end of the line, where they are unconsciously glossed over by anyone who's ever worked in a language with C-derived syntax.
- RussianCow 9y agoI hear this a lot, but in ~4 years writing JavaScript without semicolons, I've had to do this maybe two or three times. I just don't feel like starting a line with [ or ( is very common, to the point that it's a complete non-issue to me.
- tga 9y agoIn the majority of cases you can't "delete a line in isolation", because it's part of a program. You have to look around and understand what the impact of deleting that line will be -- and modify nearby lines as necessary.
- pramodliv1 9y ago> And I am paranoid You should write tests when building a project in a dynamically typed language to alleviate some paranoia anyway. As long as you have decent test coverage and use a decent linter/formatter such as StandardJS[0] or prettier[1], you'll be fine. [0]https://standardjs.com/ https://standardjs.com/ [1]https://github.com/prettier/prettier https://github.com/prettier/prettier
- sli 9y agoYeah, if your linter/build tool can't handle Javascript that doesn't have semicolons, it should be considered fundamentally broken and/or incomplete. So the question to me becomes, if the build tool doesn't correctly parse the JS that's lacking semicolons, should you really trust that build tool with the rest of your code? You already know at that point that it doesn't handle your otherwise-valid semicolonless JS correctly.
- vanderZwan 9y agoI have my VSC set up to automatically format and insert semicolons when I save. Saves a lot of hassle.
- acjohnson55 9y agoIt must be said though that CS has its own headscratchers in terms of parsing, if you choose to leave off all optional punctuation.
- ralmidani 9y agoI agree. With great power comes great responsibility. Just because you can leave out all punctuation with CoffeeScript, it doesn't mean you should.
- boubiyeah 9y agoAnd with Typescript (or a linter, I guess) you would get a nice red line on that 1 out of a million line where a ; is needed. ; are eyesores to an already fairly technical debt heavy/bloated language.
- Bahamut 9y agoThere is a nasty edge case if you concatenate scripts and use an IIFE in a script
- rattray 9y agoThere's more than just those edge-cases, but the others are rare in practice. They include +, -, `, < (JSX), ::, / (regex) and maybe a few others. There's also some odd ASI issues within class bodies. https://github.com/prettier/prettier/pull/1129 https://github.com/prettier/prettier/pull/1129 can be a useful reference (and tool!)
- the_gipsy 9y agoalso `{` after a return without value