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

In general, the code is dense and difficult to read. If you know what to look for, there are a few idioms scattered around that stand out as awkward, but save a few characters here and there. There are some pretty obvious examples right at the beginning, lines 2 and 4:

  var COMPILED = !0
  goog.DEBUG = !1
As you would expect in a weakly-typed C-style language, !0 == true, and !1 == false. JavaScript has first-class booleans, and there's not much to be gained by using one of these expressions instead of the literal it evaluates to. It only serves to save character count.

Here's another example. Starting at line 91, you get the following:

  !COMPILED && goog.ENABLE_DEBUG_LOADER && (goog.included_ = {}, goog.dependencies_ = { // ... and so forth
The above code uses commas in a particular way that usually means it comes from a minifier. JavaScript has a comma operator, which is basically just a statement separator, but it has the interesting property that it joins two statements as a single expression. As in many C-style languages, control flow operators like if and while don't require curly braces, and apply to the immediately following statement if they are absent. The combination of these two means that

  if(!foo){bar();baz();qux()}
is equivalent to

  if(!foo)bar(),baz(),qux();
which is shorter by a single character. Because the line of code joined by commas is now an expression, this also lets us abuse the short-circuit property of boolean operators, re-writing the above like so:

  foo&&(bar(),baz(),qux());
for a further savings of one more character.

You pretty much never see the comma operator in code written by humans, because it's not useful for anything. Seeing them in production code, especially the way shown above, almost always means the code came out of a minifier. That actually broke the Opera browser a few months back--apparently the parser ran out of stack space when handling a single expression consisting of over 1,400 comma-separated statements.




On the subject of minification, I see a lot of lines that look like this[1]:

  fireToken : 1 === f.tradeTokens.data.fireToken ? !0 : !1,
Why might that be a desired output from a minifier? Why not simply

  fireToken : 1 === f.tradeTokens.data.fireToken,
[1] https://gist.github.com/anonymous/5133829#file-simcityui-js-...


The original code could have been written as "condition ? true : false" and it's just not a pattern the minifier picks up on.


Probably a terrible mistake from the developer, not the minifier.

    fireToken: f.tradeTokens.data.fireToken === 1 ? true : false
In my company I see JS code like the following:

    if (!!someFlag) { /* ... */ }


Cool observations. Thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: