4 ms·
The dot one line above is the better style. Change my mind. Pasting check() .then() in node REPL gives : > check() undefined > .then() Invalid
by sloonz 7y ago
The dot one line above is the better style. Change my mind.
Pasting
check()
.then()
in node REPL gives :
> check()
undefined
> .then()
Invalid REPL keyword
Pasting
check().
then()
Gives the expected result.
More generally, Javascript rules about whether a newline constitutes the end of a statement or not are pretty confusing (at least for me), so I prefer using a form that makes it explicit when a statement continues on the next line.
- sosuke 7y agoI see your perspective but a function call on a line with just the two spaces looks like poor formatting. At a glance it doesn't appear connected to the previous line until I look at the end of that previous line. My statements end in ; Lines that begin with something other than const or let are likely function calls. If it starts with . then it is connected with the previous line and the statement isn't complete. But if you're consistent in that style that is all important. Better consistent style in a project than one style over another.
- mstade 7y agoI go back and forth on this, I can't make up my own mind let alone change anyone else's! In any case, I used to do what you do – for pretty much the same reasons – but then I've gone back to starting lines with dot (and ?, ||, &&, and other usual suspects) because I parse code left-to-right, so the presence of such a character tells me that I need to look at the preceding line(s) to get the full picture, and it doesn't so much matter if it makes things paste-friendlier. Without the dot, I've found myself move things around that shouldn't be moved around for example: check(). // Insert stuff here and things break, the lack of dot on the following line had me fooled then() I have no good answers for this, and like I said I go back and forth on this – sometimes in the same file even! I think generally I don't particularly like splitting a statement over multiple line's, but at the same time I like too keep a hard limit of the number of characters I can put on each line. First world programming problem for sure.
- gherkinnn 7y ago> a form that makes it explicit when a statement continues on the next line I prefer to know that a line is dependent on the previous by having all the dots, pipes, etc on a new line. So I skim the first few characters of every line to see what's happening. An argument not mentioned here is that having the operator on the new line results in cleaner diffs, as only one line changed. However, I don't care for that and am scared of trailing commas too.