How One Missing `var` Ruined our Launch
blog.meloncard.com
How One Missing `var` Ruined our Launch
1–10 of 223 posts
Re: How One Missing `var` Ruined our Launch
#2This 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/
Re: How One Missing `var` Ruined our Launch
#3Am 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
#4One thing you can do to help avoid this: use JSLint (or something equivalent) to check for missing var keywords. And, the obvious (as you already mentioned) coffeescript. Would love to hear of other suggestions on how to effectively debug this, especially in node.
Re: How One Missing `var` Ruined our Launch
#5Reminds 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 container. Woops.edit: initialise/declare brain freeze
Re: How One Missing `var` Ruined our Launch
#6Congrats on launching. Saying this ruined your launch is a bit dramatic. The ability to put out fires when they happened is crucial to startups. Seems like the problem only existed for a few hours. It could have been worse. Write a test and move on
Re: How One Missing `var` Ruined our Launch
#7Use jslint, Luke.
Re: How One Missing `var` Ruined our Launch
#8I hit a similar thing in some code I was writing, and ended up debugging it for about 5 hours. Couldn't figure out why when some tests ran, one of them would just die.
Turns out I forgot to use 'var' in a library function, and the tests were running concurrently, and so one clobbered the other. It was not fun.
Been using JSHint ever since.
Re: How One Missing `var` Ruined our Launch
#9Since everyone is chiming in with ways to prevent this sort of thing, here is another: js2 mode for Emacs[1]. This is a mode originally written by Steve Yegge and then modified by some other people (be sure to get that version) that actually parses the code and, among other things, highlights global variables in a different color than local ones. I find this, along with the other things js2 does, helps prevent a whole host of annoying JavaScript issues, as I type.
Re: How One Missing `var` Ruined our Launch
#10Ouch.
I always thought JS's global-variables-by-default schtick was it's worst crime, but I've never seen such terrible consequences for it up close before.
Note to self: before products get to forbes, do some load testing. Even if I am using node, with its magic event loop of invulnerability.