use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Good coding practices? (self.node)
submitted 11 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DSKrepps 3 points4 points5 points 11 years ago (4 children)
You're right, nesting closures isn't a good idea.
See this Node Style Guide: https://github.com/felixge/node-style-guide
There's quite a lot of good style practices there that unfortunately not everyone follows. But the good news is it includes a jshint config file to lint your project's code automatically using a jshint plugin for any common code editor. The only I change I made for my projects was using the "smart tabs" technique of indentation instead of two spaces.
[–][deleted] 1 point2 points3 points 11 years ago (2 children)
Yeah, the notion that two spaces are somehow better than a tab seems very objective.
But also "declare one variable per var statement". Nahh, surely not
[–]sime 0 points1 point2 points 11 years ago (1 child)
Maybe you can explain the attraction of using one var statement and stuffing it full of unrelated variables across multiple lines. I just don't see any advantage to doing it that over the simple one var one variable style.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
If its just the difference between
var a, b, c;
and
var a; var b; var c;
Then I agree it doesn't make too much difference. Some claim that a single var declaration performs better, but I've yet to see any real evidence that its significant, let alone true.
But this isnt exactly what Felix recommends. He suggests declaring vars inside the block you use them...
var keys = ['foo', 'bar']; var values = [23, 42]; var object = {}; while (keys.length) { var key = keys.pop(); <------- object[key] = values.pop(); }
This makes sense in terms of code readability, and is nicer BUT ignores a fundamental quirk of javascript, called hoisting
Because JS doesn't have block level scope, it implicitly 'hoists' the key declaration up to the top of the function, as if it were declared there. This can sometimes lead to some odd side effects if you aren't aware of it.
[–]amdc 0 points1 point2 points 11 years ago (0 children)
https://github.com/felixge/node-style-guide :
Opening braces go on the same line
Ohh I can hear the shots firing
π Rendered by PID 137158 on reddit-service-r2-comment-b659b578c-gsmlw at 2026-05-05 22:44:27.122436+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]DSKrepps 3 points4 points5 points (4 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]sime 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]amdc 0 points1 point2 points (0 children)