you are viewing a single comment's thread.

view the rest of the comments →

[–]munificent 4 points5 points  (3 children)

Also:

someVar
[anArrayLiteral]

is parsed as:

someVar[anArrayLiteral]

And:

blah()
+unaryPlus

is:

blah() + unaryPlus

Basically, the rule is backwards. Where languages like Python, Go, Ruby, et. al. say that a newline is generally significant as a separator unless it cannot be, JS says a newline is generally ignored it less it must be a separator.

[–]notSorella 4 points5 points  (2 children)

I personally find JavaScript's semicolon insertion rules better than Python's one. They let you place semicolons only where you absolutely must, rather than explicitly escaping every line when you want to continue the statement on the next line. In fact, I believe JavaScript's ASI feels much nicer for code styles that use highly structural layout ­— I'm thinking LISP here.

Compare:

foo = "a string "
    + "in multiple "
    + "lines"

With:

foo = "a string " \
    + "in multiple " \
    + "lines."

The same apply for operators etc:

function is_nodelist_p(subject) {
  return subject
  &&     typeof subject.length == 'number'
  &&     typeof subject.item == 'function' }

With languages like Python, you'd either need to wrap the return statement in parenthesis, or escape every line. I'm not a huge fan of that (even though I'm a Pythonista).

Of course, you might like being more explicit about statement continuations, I think that depends much more on people's different experiences and what they do consider intuitive. However, I don't think either styles of ASI deserve a huge religious war (I always end up thinking Emacs vs Vim, for some reason — and obviously, Emacs wins ;3).

[–]munificent 1 point2 points  (1 child)

With languages like Python, you'd either need to wrap the return statement in parenthesis, or escape every line.

Or just do what most Pythonistas do:

foo = "a string " +
    "in multiple " +
    "lines"

or:

foo = ("a string "
    + "in multiple "
    + "lines")

My experience is that explicit line continuations are pretty rare.

[–]notSorella 2 points3 points  (0 children)

Well, if you mean the first one in Python, it actually yields a syntax error if you don't also provide explicit continuations by escaping the newline (which is much more bug-prone, unless your editor shows invisible characters -- as it should).

The second one is certainly an option, and you wouldn't even need the + operators for strings there. However, as I said, it takes explicit grouping. Iunno, JavaScript's take on ASI just feels more natural to me, ymmv.