Live data from Hacker News

How One Missing `var` Ruined our Launch

blog.meloncard.com

191–200 of 223 posts

Re: How One Missing `var` Ruined our Launch

#192

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

Every language and platform has idiosyncrasies that you ignore at your peril. You choose to use JavaScript, you live with its warts.

Re: How One Missing `var` Ruined our Launch

#193
post #86
post #15

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

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

#194

This 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.…

Really smart, careful people also make mistakes. This is one of the things that can easily happen to a bright but inexperienced developer. While the numbered list is helpful, I don't think calling the programmer in question lazy, careless, or "just out to make a buck," is ok or fair.

Re: How One Missing `var` Ruined our Launch

#195
post #182

This 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" ;

I see this hideous convention used a lot when assigning nodejs modules, so you can easily comment out modules for debugging purposes (I think). Other than that, why is "[NL], b = 1" safer or better than "b = 1,[NL]"?

Re: How One Missing `var` Ruined our Launch

#196
post #152

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

Please do share.

Re: How One Missing `var` Ruined our Launch

#197
post #193
post #86

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

1i is special, sort of like 1d or 1f in C. The i refers to the imaginary number datatype. i also can be reassigned, which is a horrible design bug in Matlab.

Re: How One Missing `var` Ruined our Launch

#198

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

That is a special case. Loop headers should be considered the top of scope blocks in C. I don't know why the language designers didn't do that.

Re: How One Missing `var` Ruined our Launch

#199

Steve 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

If you're looking for a new IDE, JetBrains WebStorm does this. In the chained assignment, as well.

Re: How One Missing `var` Ruined our Launch

#200

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

After I posted, I realized this. You're correct.
Post reply on HN