Live data from Hacker News

Proposed JavaScript Standard Style

github.com

91–100 of 116 posts

Re: Proposed JavaScript Standard Style

#91
post #82
post #74

No semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as if it gave JS significant newlines. [1] and > ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble. Calling it "standard JS" struck me as pretentiou…

Totally agree. It then leads to this stupidity: "Never start a line with (, [, or `." https://github.com/feross/standard/blob/master/RULES.md#semi... Now I have 4 extra rules to remember and destructuring, amongst other things, will look like shit. And for what gain? If there was an actual gain to leaving out the semicolons, I'd be onboard but the only gain here is someone's aesthetic pleasure and someone else's aest…

It's one "extra" rule. I call it the "Winky Frown Rule" or you could less cheekily refer to it as something of a "Complete Emoji Rule": lines that start with frowns (, [, ` should be winky frowns: ;(, ;[, ;`

95% of the time I ever use a winky frown is Typescript type assertions ;(someObj)...

It doesn't impact destructuring at all because destructuring lines start with let (or const, or maybe var if you are feeling old school that day).

ASI is not very different at all from the newline rules in Python, ML, Haskell, et al... Freedom from semicolons makes ES2015 feel like the OCaml derivative it always sort of has been.

Re: Proposed JavaScript Standard Style

#92
post #69

Earlier quoted context omitted.

singlequotes for strings is very much a standard thing in JS. And two space indentation is fairly common as well. The no semicolons and space after function name are really the weird things here.

Why would you prefer single quotes over double quotes? An apostrophe is not just punctuation in English, it is necessary to preserve the meaning of certain words (like "its"/"it's"). So in a way, it can be considered to be another, albeit rare, letter of the alphabet. Now if somebody proposed to delineate strings with the character "x" everyone would agree it's a bad idea. For the same reason, using "'" to delineate…

There's also the subtle laziness that double quotes require an extra keypress (Shift). It's not a great reason to prefer single quotes over double quotes, but it is a useful reason if you are writing a lot of strings.

JS has a lot of things that key off strings (because it doesn't have a proper enum type and the Symbol type is too new for a lot of usage yet), so you type a lot of "non-English text" strings, so single quotes make a lot of sense for the majority of uses of strings in JS. English text I typically still "double quote" or `template string quote`.

Re: Proposed JavaScript Standard Style

#94
post #74

No semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as if it gave JS significant newlines. [1] and > ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble. Calling it "standard JS" struck me as pretentiou…

Everything will be fine if you don't use semicolons. My team and I haven't, for years now. It's really, really, truly honestly ok. I promise. (Only exception is for-loops)

Re: Proposed JavaScript Standard Style

#95
post #71
post #49

Earlier quoted context omitted.

In most cases[0], Js "looks" at the next line to see if it could continue the current statement, in which case no semicolon is inserted. [0] Not true for "restricted productions", which include naked returns, and some other "special" cases.

What do you mean? Would return list.map(func1) .filter(func2); work?

Yes, but this

   return
      list.map(func1)
          .filter(func2);
has never worked in the history of JS because JS terminates the return at the newline and returns undefined.

Re: Proposed JavaScript Standard Style

#96
post #88

Airbnb has a decent styleguide - https://github.com/airbnb/javascript "A mostly reasonable approach to js" but style-guides should be just that style guides ...not standards

The idea is that you stop trying to have humans match the style guide, playing trial-and-error with the linter, and instead just have a tool fix the style. We have more interesting problems to solve than matching the style guide. Computers can take care of that.

Plus then you don't have to talk about it in code reviews. It's not a very interesting topic, honestly.

Re: Proposed JavaScript Standard Style

#97
post #74

No semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as if it gave JS significant newlines. [1] and > ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble. Calling it "standard JS" struck me as pretentiou…

I think the keyword in Brendan Eich's article is maybe "be careful" rather than "don't use". Overall, Brendan Eich is mostly positive on ASI (otherwise the language wouldn't have it) and some of the article is about how if things had been left to cook longer it's just as likely JS would be a more newline-sensitive language than it is.

Particularly interesting too in the article linked is the link to the paren-free strawman proposal [1] that suggests maybe its past time that JS also drop the algol-family heritage require parentheses in the head of for/while/if for whitespace sensitivity instead (ala CoffeeScript, golang).

[1] https://brendaneich.com/2010/11/paren-free/

Re: Proposed JavaScript Standard Style

#99
post #74

No semicolons? REALLY? We've already spoke about this, people. Let's see what Brendan Eich has to say about this: > My two cents: be careful not to use ASI as if it gave JS significant newlines. [1] and > ASI is (formally speaking) a syntactic error correction procedure. If you start to code as if it were a universal significant-newline rule, you will get into trouble. Calling it "standard JS" struck me as pretentiou…

Everything will be fine if you don't use semicolons. My team and I haven't, for years now. It's really, really, truly honestly ok. I promise. (Only exception is for-loops)

According to the link, you have resort to this kind of weirdness in order to reliably omit semicolons.

    ;[1, 2, 3].forEach(bar)
To my eye, having that in my code looks far worse than just using "standard" (ha ha) semicolons.

You mention a for loop exception as well. I don't understand what that exception is, but the general message seems to be "Trust me, you can totally omit semicolons! Everything is ok! Except for all these weird edge cases, but you can just hack kludges around them!"

Re: Proposed JavaScript Standard Style

#100
post #69

Earlier quoted context omitted.

Why would you prefer single quotes over double quotes? An apostrophe is not just punctuation in English, it is necessary to preserve the meaning of certain words (like "its"/"it's"). So in a way, it can be considered to be another, albeit rare, letter of the alphabet. Now if somebody proposed to delineate strings with the character "x" everyone would agree it's a bad idea. For the same reason, using "'" to delineate…

There's also the subtle laziness that double quotes require an extra keypress (Shift). It's not a great reason to prefer single quotes over double quotes, but it is a useful reason if you are writing a lot of strings. JS has a lot of things that key off strings (because it doesn't have a proper enum type and the Symbol type is too new for a lot of usage yet), so you type a lot of "non-English text" strings, so single…

Until you mentioned it I was not even conscious of the fact that double quotes required pressing shift, yet I type hundreds of them every day.
Post reply on HN