News for hackers. Stuff that matters.
Re:How One Missing `var` Ruined our Launch by mst on Monday October 31, 2011 @06:58PM (#3179540)
Am I right in thinking that the javascript

  /* "use strict" */
construct would have caught this mistake (just like it would have done for me in perl code)? Seems to me that some such feature is absolutely and utterly necessary in any environment where you're doing a lot of closure creation ..
Re:How One Missing `var` Ruined our Launch by apaprocki on Monday October 31, 2011 @07:14PM (#3179617)
Yes:

  $ node
  > "use strict"; initial = "foo";
  ReferenceError: initial is not defined
      at repl:1:17
      at Interface.<anonymous> (repl.js:168:22)
      ...
Re:How One Missing `var` Ruined our Launch by geraldalewis on Tuesday November 01, 2011 @06:23AM (#3181411)
Yes, though never enable strict mode (in JS) unless you know exactly what it does. `use strict` causes some subtle semantic shifts that can be easily overlooked. For example, there's no dynamic binding between the `arguments` object and a function's arguments:

    ((x)-> x = 2; arguments[0] is 1)(1) # true

    ((x)-> arguments[0] = 2; x is 1)(1) # true

Any developer enabling strict mode should be testing heavily in browsers that actually support the feature. There have been a few high-profile meltdowns already (on BoA, Intel, eBay, etc.) due to devs not understanding the feature, or concatenating a `"use strict"` script (not wrapped in an IIFE) with non-strict code.

JSLint doesn't help matters, as it errors unless `"use strict"` is declared (unless run with the "sloppy" option -- something I'm sure devs love). The absolute worst scenario is for a browser to implement some kind of heuristics-based approach to respect the `"use strict"` prologue; what Brendan Eich calls a "strict quirks mode".

All that said, I'm a big fan of `strict`. It might be a good idea to use it in production, and strip the directives out when deploying.

Re:How One Missing `var` Ruined our Launch by ErikD on Tuesday November 01, 2011 @08:55AM (#3181741)
Since the code in question was run server side using nodejs you can just enable it. Using it for client side javascript is another case indeed.
Re:How One Missing `var` Ruined our Launch by bmj on Monday October 31, 2011 @08:39PM (#3179914)
Running some variation of JSLint in his editor/IDE would likely have caught this, too.
Re:How One Missing `var` Ruined our Launch by sjs on Tuesday November 01, 2011 @10:32AM (#3182182)
Or using js2-mode in Emacs. That's just one small reason why Emacs in my JavaScript workhorse. I use TextMate for most things but if I'm writing JS all day nothing beats Emacs.
Re:How One Missing `var` Ruined our Launch by Raticide on Monday October 31, 2011 @08:17PM (#3179850)
Yeah, that's all he needed. Making it a comment isn't necessary either.

Maybe Node should be strict by default? I can understand it not being the case for browsers that need to support legacy code, but for Node it doesn't really need to care about that.

Re:How One Missing `var` Ruined our Launch by morsch on Monday October 31, 2011 @09:02PM (#3179997)
Huh. On the scale from pragmatic idiosyncrasy to simply bizarre, making a string literal expression change the runtime behaviour in that manner is fairly wide towards the bizarre end of the scale.

I think, if anything, requiring it to be in a comment would have been less odd; at least comments imply a sense of "meta"-ness.

Re:How One Missing `var` Ruined our Launch by masklinn on Tuesday November 01, 2011 @05:26AM (#3181289)
> On the scale from pragmatic idiosyncrasy to simply bizarre, making a string literal expression change the runtime behaviour in that manner is fairly wide towards the bizarre end of the scale.

Yes, on the other hand it's quite necessary to not have non-compliant browsers blow up. `"use strict";` is just a noop in e.g. IE6. `use strict;` would be an error in it.

> I think, if anything, requiring it to be in a comment would have been less odd; at least comments imply a sense of "meta"-ness.

Javascript compressors definitely strip comments. They probably don't strip strings.

Re:How One Missing `var` Ruined our Launch by bzbarsky on Monday October 31, 2011 @10:35PM (#3180330)
Comments are commonly stripped by various source code processors out there, including minifiers and some browser JS engine front-ends.

The string literal doesn't make anyone _happy_, but it was most compatible with the existing widely deployed toolchains, as I understand.

Re:How One Missing `var` Ruined our Launch by kijin on Monday October 31, 2011 @11:02PM (#3180401)
Not to mention that it reeks of VB6's "Option Explicit" and "Option Strict" statements. I hated those.
Re:How One Missing `var` Ruined our Launch by apgwoz on Monday October 31, 2011 @10:34PM (#3180324)
Yeah, I always thought the string idea was wacko too, but introducing a new keyword in a language that has to be backwards compatible or suffer doom isn't a good idea either.
Re:How One Missing `var` Ruined our Launch by alunny on Tuesday November 01, 2011 @03:08AM (#3180991)
Node itself (the core js library) isn't strict mode compliant: it uses octal literals for filesystem interactions.
Re:How One Missing `var` Ruined our Launch by mst on Monday October 31, 2011 @11:52PM (#3180552)
Quite possibly a good idea.

  use v5.12;
in perl code enables strict, at least.