Maybe I am a neck beard, but hey, all those other times we blindly trusted all those companies with everything, it worked out, right?
— @steveklabnik August 12, 2012
I read The Pleasure Trap earlier this year, and was amazed at what its authors have to say about the dangers of modern food. It’s very hard to avoid unhealthy food. I wanted to get to know the authors a bit better so I searched YouTube and found this excellent hour-long video about the Dietary Pleasure Trap. It’s worth a watch if you’d like to eat better, help someone you know to eat better, or just understand why so many people are overweight. The book goes into it much more deeply and in my opinion is well worth the time it takes to read.
Avoid describing your code as automatically doing something. If you need to do multiple things at once, separate it out into a convenience function or method. Finally, make it easy to call each step explicitly. Please don’t put the orchestration code, that calls code that interacts with the outside world, into a constructor. This makes the code less flexible and harder to test. Instead, use the constructor to set up the internal state.
Update: @twitinsin points out that it’s still useful in the console for quickly declaring multiple variables.
I developed the habit of always using var when I write JavaScript long ago. At some point I got in the habit of typing var even when I’m using a JavaScript console in node or in a browser. After examining the issues I’ve decided to break that habit.
I think I got in the habit of this because I came to appreciate explicit variable declaration, and decided to gladly pay the tax. The four extra characters, including the space, isn’t bad. But it doesn’t serve a useful purpose in short console sessions. Without var
, it’s still valid JavaScript, that will run in node.js and in any browser. It won’t pass JSHint and JSLint, which is why it should always be added before delivering code.
If this gets me to be just a little quicker to fire up a REPL (a more generic term which includes the JavaScript console), it will be an improvement.
I read The Pragmatic Programmer for the first time in about 2005. I’ve thumbed through it a couple of times since. I’m going to read it again, cover to cover.
It’s a timeless book.