Actual drawbacks to omitting semi-colons?
groups.google.com
groups.google.com
I'd rather consistently have semicolons at the ends of lines than crap like this:
;(x || y).doSomething()
;[a, b, c].forEach(doSomething)
It's easier to always include the semicolons at the end of statements rather than try to figure out the edge cases where missing a semicolon would change the behavior.I'm also not a fan of the "comma-first" style, especially for var declarations...
var foo
, bar
, baz
;
I prefer: var foo;
var bar;
var baz;
It's fewer lines, consistent, symmetrical, and it's impossible to introduce errors through copy/paste or reordering. var foo,
bar,
baz;
It seems less cluttered. You can of course introduce errors through copy/paste/reordering, but I think it's a reasonable tradeoff. I agree about comma/semicolon-first being strange though.If you really hate the syntax quirks of javascript like me, a better solution is to just preprocess it. CoffeeScript has made me really enjoy writing frontend ui code again. http://jashkenas.github.com/coffee-script/
Typically I omit them if I can. And I have no reason to do so other than I think it makes the code look cleaner (I am often quite zealous on proper indentation / return lines).
I figure if using them works for you, rock on. If you hate them and don't use them, rock on. I really don't get bothered by debugging others' code either way as long as it is "readable-formatted" and works.
I've found that usually you fall into a situation where you have a company standard and have no choice in the matter though, and it doesn't even make a crap what your personal preference is.
Edit: To be fair though I only got "Eagle" on the test, but I chalk that up to only giving the test about 5 minutes of my time, too.
function x() {
return
2+3;
}
alert(x());
Every now and then I'll reformat a line by breaking it in two and it takes me 10 minutes to figure out why my code is not working. syntax match javascriptReturnError /return\s*\n\r\?\s*\w.*$/
...
highlight link javascriptReturnError Error
Obviously you can play around with the regex to tweak what matches.Edit: ninja’d by railsjedi: http://news.ycombinator.com/item?id=1762677
Just because you don't wear pants at home doesn't mean you're not going to feel silly showing up at work without them.
Here are some: http://gist.github.com/612814
Edit: Er, tried to paste code in-line but formatting got messed up.
C programmers have always used semicolons and never wasted a second thinking whether they should.
And, as one who primarily writes in Python and Ruby, I always find myself omitting them, and spending more than a second wondering why they're necessary.
e.g., print somevar, othervar; exit()
javascript - var - ';' - '{' - '}' | s/function/def/ ~= python
SyntaxError: not a chance!Same for coding conventions. Want me to use camel casing for global variables even though I think it's hideous? Fine. Want me to put closing parenthesis on a newline by themselves on a multiline function call and I put it at the end of the last line? Find something better to do with your time.
Unfortunately, I don't know enough JavaScript to know where this falls.
MyObj.item.childItem.getAll()[0].properties... // etc.
It's common to want to split this over several lines. I am in favour of placing the the period at the end of the line to indicate that the expression continues. Other people prefer the dot to start the next line instead. I don't like the latter since the first line then looks like a mistakenly omitted semi-colon.
It is customary to stack operators by indenting.
Why are lines without semi-colons at the end bad?
This "feature" is really just a bad idea. I would hope that it gets thrown out in future versions of the standard (is there one?), and use semicolons in the meantime.
Example of what I mean:
- "Do a, b, c, ..." vs - "Do a ,b ,c ,..."
This is how it is, now use your time to understand the bigger structure, not punctuation.