12 comments

[ 4.2 ms ] story [ 51.8 ms ] thread
no no and no. The first time contributor had it right.

That is the wrong way to go about it. Please do not encourage this as a best practice.

Please use eslint, proper modules and a tried and tested bundler.

I think their point was that it is outside of their control. Protect themselves from someone downloading this and installing it into their dumb pipeline.
Regardless of wether or not what amark claims is true, this is such a great example of how to approach new contributors. Well done!
Wouldn't this be better handled by the bundler instead of imposing another esoteric "magic statement" for all developers to keep in mind?
The common case of "bundling" is just concatenating files, which works fine if people add their damned semicolons.

To quote the author: "not using any semicolons at all is a very popular trend in JS these days, so it is very possible this problem might happen in the real world"

This is the crux of the problem. Javascript programmers often follow trends, not sane practice. Looking at the code, for some reason there's a semi-colon before "require" invocations as well.

I don't even know what to say, at this point. Everyone is fired.

The common case of "bundling" is just concatenating files, which works fine if people add their damned semicolons.

To quote the author: "not using any semicolons at all is a very popular trend in JS these days, so it is very possible this problem might happen in the real world"

This is the crux of the problem. Javascript programmers often follow trends, not sane practice. Looking at the code, for some reason there's a semi-colon before "require" invocations as well.

I don't even know what to say, at this point. Everyone is fired.

> The common case of "bundling" is just concatenating files, which works fine if people add their damned semicolons.

bundling is not just concatenation, and certainly not in the "common" case.

> "not using any semicolons at all is a very popular trend in JS these days

> Javascript programmers often follow trends, not sane practice

Please have a look all the popular libraries and frameworks and their codebases[1], then tell me you still think your assessment of the Javascript community is at all fair.

[1]https://www.javascripting.com/

> bundling is not just concatenation, and certainly not in the "common" case.

Fair enough, the common case is minification and concatenation. Or what else is it? The problem with the semicolon remains.

> Please have a look all the popular libraries and frameworks and their codebases[1], then tell me you still think your assessment of the Javascript community is at all fair.

Yes, it is.

https://hackernoon.com/how-it-feels-to-learn-javascript-in-2...

> Fair enough, the common case is minification and concatenation. Or what else is it? The problem with the semicolon remains.

If it is minification, then you already have a tool that process the code. The tool can easily just add the missing colon before concatenation.

The tool that does the minification isn't necessarily the same tool that does the concatenation.

Here's a very lengthy discussion on how the very popular minifier UglifyJS (version 1) originally removed trailing semicolons, causing this exact problem: https://web.archive.org/web/20130319222210/https://github.co...

In the real world, it's irrelevant what tools could be reasonably expected to do. What matters is what they actually do. Expecting your tools to insert semicolons for you is the path that leads to peril.

i dont think this is the right way to do. they should use linter instead.
Great response from the dev, I wonder if this scales for popular projects though.

I've started to use Prettier on all projects. I don't even bother with things like these anymore. If the code is valid, it'll format my JS code uniformly, and if it's not I get a big red error telling me something up, precisely at line:x. I'm not sure if it would catch the edge-case this `;` at the beginning of the file is trying to solve though.

>In technical terms: Prettier parses your JavaScript into an AST (Abstract Syntax Tree) and pretty-prints the AST, completely ignoring any of the original formatting*. Say hello to completely consistent syntax!

It's like go fmt for Javascript.

https://github.com/prettier/prettier

If you're aren't using this you probably should to avoid bikeshedding in your team.