Live data from Hacker News

Habits of a Happy Node Hacker

blog.heroku.com

21–30 of 56 posts

Re: Habits of a Happy Node Hacker

#21
post #19

#4 seems spurious. Just another example of "If everyone did it my way, then everyone would be doing it my way." What if people don't want to do it your way? What if people can actually remember to spell correctly? EDIT: *nix has case-sensitivity so that people can actually use it.

It isn't about spelling. It's about behavior that will be presumed correct in one environment but not in another. It's about portability.

For another node example - in Linux, you can successfully use paths like `let filepath='foobar/' + filename`. That's correct in the given environment. However, such code will break when run in Windows. This is why `let filepath = path.join('foobar', filename)` is a superior solution.

A Windows or OSX user can save Myfile.js all day long and require('MyFile') with success. That same code will break as soon as you try to run it in Linux.

These recommendations are the product of supporting the many thousands of Node apps built each week on Heroku.

Re: Habits of a Happy Node Hacker

#24
post #19

#4 seems spurious. Just another example of "If everyone did it my way, then everyone would be doing it my way." What if people don't want to do it your way? What if people can actually remember to spell correctly? EDIT: *nix has case-sensitivity so that people can actually use it.

It isn't about spelling. It's about behavior that will be presumed correct in one environment but not in another. It's about portability. For another node example - in Linux, you can successfully use paths like `let filepath='foobar/' + filename`. That's correct in the given environment. However, such code will break when run in Windows. This is why `let filepath = path.join('foobar', filename)` is a superior solutio…

Thanks for the reply. While I understand the argument about preventing pitfalls, it's reasonable to expect programmers to pay attention to capitalization, since source code requires you to anyway. I think the path of least resistance here, is to tell programmers to spell things the same way as the last person to work on the code spelled it.

Re: Habits of a Happy Node Hacker

#25
> Cluster your app

How is this possible in my multiplayer game where the whole world lives in the program? E.g. var map = [...] and then map[x][y] when I want to use it, var players = [], players.push(newPlayer) etc. How can I share this state in a cluster?

Re: Habits of a Happy Node Hacker

#26
post #25

> Cluster your app How is this possible in my multiplayer game where the whole world lives in the program? E.g. var map = [...] and then map[x][y] when I want to use it, var players = [], players.push(newPlayer) etc. How can I share this state in a cluster?

Well, you're main app should obviously not be clustered but think about the api you use to manage data. I don't know your architecture but I'm sure that you can separate your api from your user state and cluster those apis as well as use various reverse proxies and load balancing services.

Re: Habits of a Happy Node Hacker

#27
post #25

> Cluster your app How is this possible in my multiplayer game where the whole world lives in the program? E.g. var map = [...] and then map[x][y] when I want to use it, var players = [], players.push(newPlayer) etc. How can I share this state in a cluster?

You need some form of IPC. Easiest thing that comes to my mind is just to use a redis hash.

Re: Habits of a Happy Node Hacker

#29
> As long as each dependency is listed in package.json, anyone can create a working local copy of your app - including node_modules - by running npm install.

But it is going to download the internet, will take forever, and if the network is patchy, any dependencies that weren't downloaded will remain unresolved, even if you reinstall the package, and you'll have to manually install them with the help of `npm list`, or nuke node_modules and start over, and pray that this time the network remains perfect for a few minutes at a stretch.

(someone please tell me I've got it all wrong)

Re: Habits of a Happy Node Hacker

#30
Thanks Hunter. That was a really helpful article.

Though I don't agree with every suggestion, memory tuning and clustering are both really important and not discussed widely enough. save-exact is a good tip too - I've just been mass-deleting the carets before committing.

Post reply on HN