How One Missing `var` Ruined our Launch
181–190 of 223 posts
Re: How One Missing `var` Ruined our Launch
#182 var a = "foo",
b = "bar",
c = "baz";
All it takes is one missed comma and all of a sudden you've turned a lot of your variables global.Re: How One Missing `var` Ruined our Launch
#183Am 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 ..
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…
Re: How One Missing `var` Ruined our Launch
#184Reminds me of one of the more confusing bugs I've ever encountered in my life. I was throwing together a quick UI with Adobe Flex, and for some reason every time you clicked a particular button, the entire UI would shift 20 or so pixels to the right. I spent hours scratching my head until I noticed this for loop: for (x=0;x I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI…
Now that I understand what you're saying: This is one of the reasons I hate the "feature" in C++ and C99 that you can declare variables anywhere. If you stick to declaring all your variables in one place, it's much easier to notice when you've already used a variable name.
Re: How One Missing `var` Ruined our Launch
#185Re: How One Missing `var` Ruined our Launch
#186This is why I like both Scala and Coffeescript approaches. On Coffeescript vars are created for you, and on Scala, you can't not use it (you either use var or val, making it easy to change from re-assignable variables to final ones). Note that nowadays going to Coffeescript from Javascript is quite easy: http://js2coffee.org/
I imagine that must be a headache for non-native speakers for whom "l" and "r" are indistinguishable. Imagine coding in a language developed in China with keywords "mā" and "mǎ"… most English-speaking developers would never remember which one to use because they can't distinguish between the two verbally.
Re: How One Missing `var` Ruined our Launch
#187Earlier quoted context omitted.
Why does threading matter? You can have multiple JS global objects all running on the same thread. See any web browser.
Well I don't think web browsers are really the same thing as server side code. Even individual pages in a browser are sandboxed from each other. Just like individual request/response cycles for a user session probably should be on the server (unless you go out of your way to break that, ie making some variable "static").
Re: How One Missing `var` Ruined our Launch
#188Reminds me of one of the more confusing bugs I've ever encountered in my life. I was throwing together a quick UI with Adobe Flex, and for some reason every time you clicked a particular button, the entire UI would shift 20 or so pixels to the right. I spent hours scratching my head until I noticed this for loop: for (x=0;x I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI…
Re: How One Missing `var` Ruined our Launch
#189This is why I really dislike it when I see var a = "foo", b = "bar", c = "baz"; All it takes is one missed comma and all of a sudden you've turned a lot of your variables global.
var
a = "foo"
, b = "bar"
, c = "baz"
;Re: How One Missing `var` Ruined our Launch
#190Am 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 ..
Running some variation of JSLint in his editor/IDE would likely have caught this, too.