New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revisiting the style guide? #14506
Comments
What are you basing this on? IIRC the last time we tested this, there was no difference for
Definitely agree with this change, if there are no issues with IE (we still do want to support at least IE 10 and 11 right?). |
Yeah, some numbers would help on this decision.
My brain reads that like this:
JS interpreters remove that comma these days? |
I personally do not vote to allow trailing commas in multiline arrays since I find it unusual to read, too. |
For me the purpose of trailing commas is that it makes it quicker to add and remove things, as well as reorder them by cut / paste. No need to worry if you just cut the last item or not, every line is the same. As for seeing On the other hand, I don't think it matters either way. The switch to |
We're not transpiling, are we? Rollup just replaces ES6 import/export syntax while leaving everything else alone, unless you add plugins like rollup-plugin-buble. But |
The trailing commas also serve a much larger purpose than just "ease of use". In larger projects where lots of people contribute to, it's useful to use things like So, stating the obvious here: If there are things listed on multiple lines that were added by @mrdoob, and I would later add a line there, my name would be shown on the last line of code that I didn't write. I'm personally against the use of trailing commas for the exact same reason as the people stated before me, but I do see the benefits and I am getting used to it now that we also enforce this in the office since this year.
Yep. Regarding the use of The difference between See this post for an elaboration (make sure to run the actual snippets to see that the difference is pretty much neglectable now): https://stackoverflow.com/questions/37792934/why-is-let-slower-than-var-in-a-for-loop-in-nodejs The accepted answer of that SO-question also points out the differences between The use of Just my 2 cents. For reference: |
The trailing commas is one of the best js patterns i've seen and makes diffs much more legible. |
All browsers have been fine with that comma in arrays and objects for > 10yrs except IE Let me add rather than looking at it as strange thing another POV is that the syntax is actually the comma is required it's just browser gives you a break and doesn't require the last one. One person's strange is another person's beautify. I find the consistency of every line being the same more personally pleasing than the last line being different. Of course those are personal preferences I'm just bringing them up another way to look at things. as for diffs I found these comparisons online no trailing comma diff adding a line trailing comma diff adding a line |
Let me add one more POV for trailing commas 😜 You can see trailing commas as similar to semi-colon This is perfectly legal code
The last line missing the semi-colon. One POV is to see comma as the same thing. Maybe it's like the people/lamp illusion. Whether you see 2 people or a lamp stick both are valid. But in that case, with comma since both POVs fit ("comma on end looks like , undefined" vs "comma missing looks inconsistent") one has objective benefits and the other doesn't so ...? |
@mrdoob The output format should be set to |
Closing in favor of #6419. |
I'm sure this is opening a can of worms but the [style guide] seems a little dated and I'd like to suggest 2 changes
prefer
const
andlet
tovar
?I don't know why
var
is preferred (was told to change to var in a recent PR). My guess is because that's where it started and becauseconst
andlet
are new. But now that code base is using ES5 modules it seems like any reason for keepingvar
is long gone. Because of theimport
lines, for code to work on browsers that only supportvar
the code has to be run through a transpiler. That same transpiler is/will already convertconst
andlet
tovar
.Further, there are concrete objective positives to using
const
andlet
overvar
. Both are scoped to braces instead of function scope. Neither create global variables unlikevar
. Sure, much of the code usesvar
now (although IIRC eslint can auto fix that). Changing the linter to requireconst
andlet
and slowly changing legacy code over will prevent more errors and leaks. Also withconst
andlet
used everywhere it's possible the enable eslint checking for more undefined variables which at least for me as been a huge help.There was a time when
var
was faster but that time is long gone.Is it time to stop using
var
?allow trailing commas in multiline arrays and objects
This might be a personal preference by Mr. Doob but my guess is more that it's left over from IE days. IE didn't support a trailing comma but now that transpiling is happening the trailing commas get removed by the transpiler for IE compatibility. For devs trailing commas are a win as they lead to less errors. Errors that are usually caught but errors that often require at least one iteration to catch, running in the browser and seeing the syntax error then going back and editing commas. At least in my experience trailing commas avoid that issue.
By trailing commas in multiline arrays and objects I mean for example
and
With trailing commas adding or removing lines requires only dealing with a single line. With trailing commas it means always having to be aware the last comma is and removing it or adding it.
Of course whatever is decided is fine, I'll follow the guide for PRs. I just thought I'd ask as the code switched to ES5 modules if it was time to revisit some of the style guide (note the
var
part is not actually in the style guide.)The text was updated successfully, but these errors were encountered: