Hacker News new | comments | show | ask | jobs | submit login

Ending every line with // is noise because it means nothing to the compiler or to the human. If I could write comments without prefixing them with //, I would (but the compiler won't let me). () and ; are not noise because they simplify the rules of the language. They make it so someone reading your code needs to remember fewer esoteric rules to understand it. That is a big win. Saving a single character of typing per line, for your fingers and your disk, is a miniscule win. I hope you're writing code that's more interesting than a typing contest (but if you aren't, maybe you care about the semicolons). The disk and the network don't care about one more semicolon per expression. They know about compression, they will deal with it. If your compiler doesn't complain when you miss them, you need a better compiler. Maybe a linter, or google's closure. Or maybe there's a market for a decent javascript compiler. I don't understand what you mean by "when semi-colons fade into the background, it is MUCH harder to catch the one case where they are important". If you use them everywhere and you miss one, it's easy to spot. If you have to examine each line with a set of rules in order to figure out if you actually needed one there, that's a more expensive task.

Ruby, python, and coffeescript were designed with significant newlines, and therefore designed around the corner cases. The only reason you'll need semicolons in those languages is to have two statements on the same line (coffeescript excepted, I'm not sure about it but my guess is that they did it right). These languages went to great lengths to reduce the cases where you need statement separators, and document this behavior widely and clearly. Perl requires semicolons, dunno where you got the idea it didn't. I don't know about smalltalk and go, I don't use them.

I probably did miss what you were trying to say.

In languages that weren't designed with significant newlines, everybody uses the statement separator at the end of a line, so it seems to me that moving them to the beginning of lines is just confusing. In any case, ASI is not significant newlines, it's a hack. I don't know what more to do than to just beat it into your head. It is not a feature you should rely on.

The important part of what I'm trying to express is that, in any language, the most important thing you need to do is to write explicit code. This means typing all the characters so that not only does the compiler (and tools) not get confused, but future human readers don't get confused either. Javascript intends for you to separate your statements with semicolons. If you start playing tricks with them, you are going to confuse people that try to understand (or, heavens, learn from) your code. You will get burned.

Consider this example (I'm a C guy):

    if (a && b || c && d | e || f && g)
How does this resolve? Does it help you if I write this?

    if ((a && b) || (c && (d | e)) || (f && g))
It sure as hell does. Now, these are semantically identical. But when you read the second one, you don't need to know that bitwise OR binds tighter than logical AND, and logical AND binds tighter than logical OR. These are details you should not need to remember when you read my code. Are parentheses just line noise here? I think not. I think they are quite meaningful. Not to the compiler, but to the human consumers of my code. It's costs the reader a lot more to read the first one than the second. The first one is mentally expensive. (In fact, modern C compilers will warn you about not having these parens here because they know that adding them is a good idea. If you turn on warnings.)

The same applies for ASI. If you rely on extra compiler tricks a human needs to remember, that's expensive. It is a lot better to have a simpler rule: just put a semicolon after every statement, and don't make anyone think about it again. Or put one before, I don't really care. Just do something consistent. Try to code to a simpler subset of the language, to make other programmers' lives easier.

I really don't mean this to be an attack against you or the javascript community. Well, I sort of do, because abusing ASI is stupid, but I actually mean this to be an educational experience. Let me help you mature as a programmer.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact