
Twitter crashes itself with commas - MatthewPhillips
http://my.opera.com/hallvors/blog/2012/07/17/twitter-crashes-itself-with-commas?1
======
gamache
For the love of god, please someone tell me what is so offensive about the
semicolon.

When you replace a thousand of them with commas, nothing has been gained!

When you start placing them only at the beginning of certain lines, subject to
JS's parsing rules, you are thinking more, not less!

~~~
tomjen3
It shouldn't be necessary to write them in the first place.

Anyway in this case I guess some automatic code reduction tool has decieded
that four characters can be saved by changing it to commas. I doubt it was
written that way to begin with.

~~~
shaggyfrog
It shouldn't be necessary for me to look both ways before I cross the one-way
street in front of my home. But I do.

------
saurik
The title of this post was changed from "Lack of semicolons causes Twitter to
crash in Opera" to "Twitter crashes itself with commas", long after it hit the
front page (and in fact got all the way to #2); this sadly drops the (as far
as I'm concerned) critical note that this bug only affects Opera, and makes it
sound like this is Twitter's fault, when this is really Opera's fault.

On the other side, this is why many of the comments, including the top
comment, seem overly invested in the notion of semicolon insertion, as opposed
to looking at the specific usage of replacing sequences of
ExpressionStatements (even if separated by semicolons) with a single
ExpressionStatement holding a very long compound Expression (separated by
commas).

------
tseabrooks
Headline makes it sound like there is a bug with Twitter. In reality they are
doing something totally legal, if a little gross to look at IMO (C / C++
embedded coder by training).

The actual bug appears to be not a bug so much as a limitation in the Opera
parser with regards to how many comma delineated calls it can handle at a
single time. Somewhere around comma 1019 things get messy.

~~~
colanderman
The headline used to mention Opera. Then an overzealous mod edited it to match
the page title, which leaves out the context that this is an Opera-specific
blog.

~~~
tseabrooks
I agree, over zealous mods are really having a negative effect on this site
lately with submission renaming.

In this case both the current title and the original title (if memory serves)
give the impression that twitter is somehow at fault.

~~~
Yver
"give the impression that twitter is somehow at fault"... which it is. This is
definitely partly Twitter's fault for craming all of their code as one
humongous instruction (comma) rather than multiple lines (semi-colon.) It's
also obviously partly Opera's, for not handling terrible code such as
Twitter's as well as they should have.

~~~
tseabrooks
I'm not sure I agree...

"Terrible code" is this sort've nebulous subjective thing. Clearly, to you and
I, this is terrible code, though probably created by a minifier / compiler.

Lots of code can be terrible (We've all written some in our time). However, if
terrible code is valid it's the interpreter's (in this case) problem to figure
it out. The ECMAScript spec is nightmarish but we get the spec we deserve :).
Twitter has ZERO fault here. They wrote terrible _valid_ code and the parser /
interpreter should be spec conformant no matter the pain.

~~~
MatthewPhillips
I would say that not accounting for a browser bug is definitely their fault.
Remember that they have a responsibility to their users to make their site
work by accounting for bugs. Designers spend a lot of times meticulously
working on CSS to account for all of the various browser rendering quirks.
Developers need to put the same care into their JavaScript.

Perhaps Twitter has chosen not to support Opera which is fine by me (even
though I'm a user), but I think more than likely this was a slip-up in their
QA process.

------
samarudge
From the comments

> I believe it's Google Closure compiler putting commas in there.

Someone else linked to an explanation of why

> [http://blog.vjeux.com/2011/javascript/javascript-comma-
> trick...](http://blog.vjeux.com/2011/javascript/javascript-comma-trick.html)

</fact><opinion>

So from the looks of it, the problem is in Opera's javascript implementation.

I'm not sure how much Google uses Closure Compiler internally but I wouldn't
have thought they would use code they knew to cause issues in some browsers. I
guess that ether means the Opera implementation is wrong and the code should
work fine, or Google didn't test this as fully as they should have done

~~~
tseabrooks
Is it a bug though? Sounds like a conscious design limitation in the parser. A
bad limitation, but not a bug. Sounds like it's behaving "as expected".

~~~
mistercow
ECMAScript is a language with an ISO standard behind it. Any time a parser
doesn't comply with that standard, it's a bug.

------
greghinch
Can someone please provide a valid, technical reason for not using semicolons
other than "it doesn't say I hafta so I'm not gonna!" (that quoted bit should
be read as if a 5 year old throwing a tantrum was saying it)

~~~
mdavidn
JavaScript minifiers use commas to avoid braces in control statements. The
following two statements are functionally identical. Apparently the Closure
Compiler goes overboard and just uses commas everywhere, even when the comma
offers no length advantage over semicolons.

    
    
      if (a) { b(); c() }
      if (a) b(), c()

~~~
sjwright
Can someone please provide a valid, technical reason for not using braces
other than "it reduces my file sizes by one percent prior to gzipping zomg!"

~~~
mistercow
But reducing file sizes by one percent, if done by an automatic tool, is a
perfectly worthwhile reason. You don't need any other justification.

Or you wouldn't, of course, if it weren't for some browsers being broken and
unable to handle it.

~~~
greghinch
Ok, but any front-end engineer worth their salt should be used to the fact
that the browser will never be a perfect implementation environment and be
willing to adapt around known issues to produce functional code that works for
your users. They aren't going to notice that 1% file size. They are going to
notice your page not working.

~~~
shock3naw
A 1% reduction in output at Twitter's scale isn't as paltry as you might
assume. Engineering decisions are made for both server-side and client-side
reasons.

You're making a blanket statement about Twitter developing bad code because of
a recent bug. It will be fixed.

~~~
GrumpySimon
Yes, saving 1% of a few million requests a day is not a trivial savings.

~~~
mistercow
I kind of wonder about that reasoning, though. I mean, no it's not trivial if
you imagine having to foot the bill for it yourself, but proportional to the
kind of money Twitter is dealing with, it's, well, still just 1% of a JS file.

But I don't think we need to think of it in terms of Twitter's scale at all.
The point is that saving 1% for basically free, is saving 1% for basically
free, and that's worthwhile no matter how big you are. On its own, it's a drop
in the bucket, but the cumulative effect of many small low-opportunity-cost
savings is a significant low-opportunity-cost saving.

------
dherman
This headline is misleading, especially given how much people love to argue
about semicolon insertion. This has nothing to do with semicolon insertion.
It's just about an artificial constant limit in how large a certain type of
parse node (comma expression) can get in Opera's JavaScript parser. (Of
course, Twitter should have tested in Opera!)

------
falcolas
I guess I'm most surprised (alarmed?) that there is 4 mb of Javascript that
has to be executed on a Twitter page.

~~~
evilduck
Maybe 4mb of memory required in the compilation step, the file mentioned in
the article, "t1-more" is only 355kb over the wire.

~~~
falcolas
> that "bundle/t1-more" file is a whopping 4 129 653 characters.

I'd have to imagine that 355kb is the compressed size, but that character
count (assuming one byte characters, not UTF8) works out to be 3.938
megabytes.

That's a lot of code. Even more when you consider it's been minified.

~~~
slig
Does anyone have the numbers of Gmail JS size?

~~~
bgarbiak
According to Firebug: roughly 250 KB is transferred, half of that is lazy
loaded (after DOMready, I suppose) and it looks like the biggest file (75KB)
is from Google+. All scripts uncompressed (not un-minimized) weigh about 740
KB.

~~~
falcolas
Makes me wonder if it's the difference between a different language being
compiled to minified Javascript vs. minified Javascript.

------
cpeterso
Somewhat off-topic, but: why semicolons?

C, Pascal, and ALGOL (1958) use semicolons as a statement delimiter. Why was
the semicolon chosen instead of, say, the period or newline? BCPL (like JS and
Go) allows semicolons to be omitted if a statement ends unambiguously on one
line.

Was the semicolon a QWERTY home row key before or after ALGOL?

~~~
chimeracoder
For what it's worth, there's a precedence for it in formal, legal-style
writing. UN resolutions, for example, are always written as a single
sentence[1].

It makes sense when you think of an entire resolution (program) as a single
goal (output/result), which involves many separate steps/clauses (statements)
that need to be executed.

A period is a terminator; it says 'This thought ends here', while a semicolon
is a delimiter (ie, the clauses it separates are independent grammatically,
but not contextually).

[1]<http://web.utk.edu/~modelun/resolutions.htm> (Model UN rules, but you get
the idea).

~~~
mkopinsky
I have seen the same thing in mayoral declarations or the like.

    
    
       Whereas John Q. Doe is an upstanding citizen who has contributed to the city, and
       Whereas aforementioned Mr. Doe is an awesome dude, and
       Whereas some people who happened to contribute to my campaign are fans of Mr. Doe,
       Therefore, I, Mayor Wile E. Coyote do hereby declare Octember 31st, 2012 as John Q. Doe Day in the city of Acme, CO.
    
    

In this context, the UN resolution is actually similar to the comma-style used
here by Twitter. We don't want the statement/sentence to end, so we use
semicolons/commas to make it continue, and end up breaking browsers/non-lawyer
readers.

------
the_mitsuhiko
It's very common for javascript compressors to reduce statements to
expressions if that's possible. Even uglify-js does that and that ones is not
particularly amazing.

------
ekoontz
Not sure if this is related, but starting yesterday, I've had to switch from
Firefox to Chrome for twitter - Firefox uses all my RAM and beachballs.

------
Achshar
I remember reading about some twitter dev who apparently hated semicolons and
went far and beyond to avoid putting semicolons. He was a bootstrap dev i
IIRC. I tried googling but couldn't find anything again. maybe this is
related?

~~~
bgarbiak
You probably mean this: <http://news.ycombinator.com/item?id=3842713> But
that's rather unrelated.

------
soulclap
I saw a couple of tweets today by Chrome users who were wondering where the
'new tweet' input form field went. So not sure if this problem is limited to
Opera. (I am using Chrome as well and didn't have any problems but still.)

------
madrona
Commas are such an idiotic, navel-gazing, Javascript hipster douchebag
convention.

------
ericcholis
I found the lack of semicolons annoying when reading the Bootstrap jQuery
plugins.

Although, if I'm not mistaken, the exclusion of the semicolon is technically
correct. So, both parties are at fault here.

------
mvzink
Further context/information: <http://news.ycombinator.com/item?id=3584635>

