question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Revisiting the style guide?

See original GitHub issue

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 and let to var?

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 because const and let are new. But now that code base is using ES5 modules it seems like any reason for keeping var is long gone. Because of the import lines, for code to work on browsers that only support var the code has to be run through a transpiler. That same transpiler is/will already convert const and let to var.

Further, there are concrete objective positives to using const and let over var. Both are scoped to braces instead of function scope. Neither create global variables unlike var. Sure, much of the code uses var now (although IIRC eslint can auto fix that). Changing the linter to require const and let and slowly changing legacy code over will prevent more errors and leaks. Also with const and let 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

 const sizes = [
     100,
     200,
     300,
 ];

and

 const options = {
    width: 100,
    height: 200,
    depth: 300,
};

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.)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

10reactions
Mugen87commented, Jul 19, 2018

I personally do not vote to allow trailing commas in multiline arrays since I find it unusual to read, too.

7reactions
greggmancommented, Jul 26, 2018

JS interpreters remove that comma these days?

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Style Guide: How To Write One for Your Brand
A brand style guide can prevent branding fails, ... your mission statement is filled with corporate jargon, it's probably worth revisiting.
Read more >
What Is a STYLE GUIDE? - YouTube
What does a Style Guide include? And why you definitely need to put it together – learn more in this video.
Read more >
Revisiting the Model Statement of Style
Ken Adams is the leading authority on how to say clearly whatever you want to say in a contract. He's author of A...
Read more >
How to create a brand style guide - 99Designs
A brand style guide takes the heart and soul of your brand and translates it into design. We'll teach you the 5 essential...
Read more >
Kyle revisiting Residential Style Guide and targeting front ...
By Anita Miller Proposed changes to the city of Kyle's Residential Style Guide are intended to create a “higher standard” in neighborhood ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found