Live data from Hacker News

How One Missing `var` Ruined our Launch

blog.meloncard.com

21–30 of 223 posts

Re: How One Missing `var` Ruined our Launch

#21
post #5

Reminds 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…

Classic! I did that with rotation in my js gaming engine once, fun times.

Re: How One Missing `var` Ruined our Launch

#22
> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line.

jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.

Re: How One Missing `var` Ruined our Launch

#23

One 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.

Indeed, JSLint or JSHint would have cought this. The claim that "nothing I could do in best practice ... would have caught the offending line" is false.

Re: How One Missing `var` Ruined our Launch

#24
post #22

> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line. jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.

Even better is setting your editor to run JSHint when you save a .js file, and let you know if there are problems. Not only does it avoid stupid bugs, it saves time round-tripping to the browser for trivial issues like syntax errors.

Re: How One Missing `var` Ruined our Launch

#25
post #16

I feel for you man, but did you not test with more than one user at the same time? I live in constant fear of this kind of thing, I always round up as many people as possible to test at once.

Screw rounding up >1 users for testing (though it does give needed human insight), if you aren't spooling up a few multicore VMs with JMeter or better, you aren't really performance testing.

Re: How One Missing `var` Ruined our Launch

#28
post #9

Since 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 whol…

Have you had any luck getting it to handle modern JavaScript style? Whenever I've tried js2-mode it really hasn't liked jQuery style nested anonymous functions.

Re: How One Missing `var` Ruined our Launch

#30
post #24
post #22

> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line. jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.

Even better is setting your editor to run JSHint when you save a .js file, and let you know if there are problems. Not only does it avoid stupid bugs, it saves time round-tripping to the browser for trivial issues like syntax errors.

Sounds like a good idea. I know emacs flymake mode can be set up to underline problems detected by jshint. Personally I like to have the tests and jshint run by a hotkey so I can happily move the code through invalid states (towards a valid goal) without being constantly complained at :)
Post reply on HN