How One Missing `var` Ruined our Launch
191–200 of 223 posts
Re: How One Missing `var` Ruined our Launch
#192This was a problem of laziness more than anything else. To the beginner developers out there: Learn to write good code and to pay attention to the details. Don't become just another co-founder trying to do the bare minimum just to make a buck. Take pride in your work and use best practices. Be careful to avoid the careless mistakes made by the author... 1. Did a major last minute code change 2. Did not run jslint 3.…
Sure, blame the victim, not the idea that default variable scope is global.
Re: How One Missing `var` Ruined our Launch
#193Earlier quoted context omitted.
Ha, that reminds me of a program I was writing in MATLAB. I used `i` for a loop index in one part of the script and then later when doing some complex number calculations (`2 + 3i`)...it was one of those so-stupid-you-have-to-laugh moments when I finally figured it out.
It's for this precise reason that I use 1i rather than i when doing complex arithmetic in matlab.
Re: How One Missing `var` Ruined our Launch
#194This was a problem of laziness more than anything else. To the beginner developers out there: Learn to write good code and to pay attention to the details. Don't become just another co-founder trying to do the bare minimum just to make a buck. Take pride in your work and use best practices. Be careful to avoid the careless mistakes made by the author... 1. Did a major last minute code change 2. Did not run jslint 3.…
Re: How One Missing `var` Ruined our Launch
#195This 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.
that's why many people favor this variant: var a = "foo" , b = "bar" , c = "baz" ;
Re: How One Missing `var` Ruined our Launch
#196You will probably get hundreds of comments with unsolocited advice, but let me just say to checkout and setup JSLint: https://github.com/douglascrockford/JSLint Setup and how you use it is more important than just using it. I run it in three places: 1) In my IDE (bound in vim on save, same in TextMate) 2) As a Git checking hook 3) In deployment / build scripts Turn all the warnings way up and it always catches redecl…
Re: How One Missing `var` Ruined our Launch
#197Earlier quoted context omitted.
It's for this precise reason that I use 1i rather than i when doing complex arithmetic in matlab.
Wait... matlab allows "AB" to be inferred as "A*B"? How is that not a disaster? Parsing a token that doesn't even exist in the lexer stream? Even C++ wouldn't try that.
Re: How One Missing `var` Ruined our Launch
#198Earlier quoted context omitted.
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.
Umm, I find the opposite to be true. By always declaring variables where I use them (notably in for loops), I avoid accidentally reusing a variable I used elsewhere.
Re: How One Missing `var` Ruined our Launch
#199Steve Yeggae's js2-mode highlights globals during editing, and it's saved me a good many times. http://code.google.com/p/js2-mode/ Mind you it won't catch globals declared in chained assignments eg var x = y = 0; // y is defined globally
Re: How One Missing `var` Ruined our Launch
#200Earlier quoted context omitted.
Excellent advice. You simply have to understand JS scope rules, and the Crockford post lays it out compactly. It's an idiosyncratic language.
I think the author of the blog post understands JS scope rules. His point isn't that you shouldn't need to have a "var" in front of your declarations or that javascript is stupid and he doesn't understand it, it's that there should be a better way to find bugs like the one that bit him. Of course, there is a way to find his particular bug (JSLint, "use strict") that he didn't know about. Still, the point about debugg…