5 ms·
The author doesn’t seem to work in a team where the code is going to be touched by multiple people, all with varying levels of competence. It’s easy to explain
by robin_reala 16y ago
The author doesn’t seem to work in a team where the code is going to be touched by multiple people, all with varying levels of competence. It’s easy to explain to your colleagues that JS should have semi-colons added or weirdness can happen. It’s less easy to say ”Here’s the ECMAScript spec, go read it“ when they’ve got ruby and HTML and CSS and SQL to write and simply don’t have the time to thoroughly master each and every part of the stack.
- olavk 16y agoThe point is that always adding semicolons does not solve the weirdness problem. Consider: return 17 This returns undefined, which is counter-intuitive if you come from other c-style syntax languages. But if you say "always terminate statements with a semicolons, otherwise weirdness happens", the intuitive fix is: return 17; Which still doesn't solve the problem. You have to remember an additional rule: "Don't insert line breaks in the middle of a statement, if the line break could be interpreted as a statement terminator." Or to put it another way: If you are in doubt, don't use a line break. The problem isn't really if statements should be terminated with a semicolon or not. The problem is to decide when it is safe to insert a line break when it is not intended to terminate the statement.
- gcr 16y agoWhoever linebreaks return statements like that deserves what's coming to them. But I get what you're saying. Simple, consistent rules are better for teamwork.
- pdw 16y agoI do that sometimes (obviously not in JavaScript), to split up long lines in situations such as this: bool is_foo_possible() { return test_first_condition() && test_second_contition() && test_third_condition() } I don't think that's very horrible.
- BrandonM 16y agoI would tend to write that: bool is_foo_possible() { return test_first_condition() && test_second_contition() && test_third_condition() } I prefer to put my infix operators at the beginning of continuation lines, because that makes it immediately clear from a glance that it's a continuation line.
- IsaacSchlueter 16y agoI do this as well. For a while, I tried to stick to the rule that "return\n" was not allowed. When I meant to return undefined, I'd write "return undefined". In the end, I abandoned that rule, because too many of my functions return undefined. But it's kind of a nice thing. When I do get around to building that linter, I might make `return\s*\n` verboten.
- olavk 16y agoYou could just write "return;", that would make it obvious that no value is returned.
- gcr 16y agoOH. Good point.
- deleted 16y ago[deleted]
- cancelbubble 16y agoHe used to work at Yahoo. That's where I met him and while I never worked on a team with him, he seemed like a nice guy. Definitely smart, though his blog/writing style may come across as arrogant to some. I would have loved to end up on a team with him as I'm sure I could have learned a lot from him.
- IsaacSchlueter 16y agoThanks :)