Wednesday, March 07, 2007

Five simple ways to boost self-productivity

It is said that really good programmers are orders of magnitude more productive than the average ones. What makes this the case? And why isn’t this the case in other industries? I believe the answer lies in that computers are very good at automation. And good programmers know how to make computers do what they do best: that is, automate things. The best programmers are the ones who undersand this so well that they will not only solve the task they are directly working on, but learn to automate every step of the very process that leads them there. Here are some useful tips that may seem like common sense, except that most good programmers never go from good to great because of this.

1. Never look when you can search. This is a big one that irritates me to no end when I sit next to someone who is looking through a list of files. Why look when you can search? Even if you’re looking for one item in a list of ten, it is always faster to type three or four characters than to scan the list with your eyes. Unless of course you’re a really slow typer, in which case you might want to take a keyboarding class or choose a different profession. Most reasonable environments including the popular editors and IDEs offer at least some way to do inline completion-based searching. Hit the shortcut and type the first couple characters identifying what you’re looking for and you’re there.

2. Don’t repeat yourself. This is a big mantra today, but it applies to a lot more than programming. It’s a way of life. Are you typing the same thing over and over? Make a shortcut out of it. There are plenty of ways: shortcuts are often built into the programs that you use, learn them. Use operating system features to set shortcuts for things that don’t have them. On Unix, alias is your friend. Make two character mnemonic aliases for everything. Corollary: Never Mouse when you can Key. A good approach to learning built in shortcuts is every time you reach for your mouse, make a note of the shortcut key for the action you’re performing, and then let go of the mouse and execute the action from the keyboard. Then do it two more times.

By the way, if you’re not using Opera you’re probably missing out on the coolest keyboard automation ever. In Opera you can actually navigate to any link on the page instantaneously. Hit Ctrl+J to see a list of links, then just type the first few characters of the link name to get there. If you don’t understand how powerful this is, time how long it actually takes you to reach for the mouse, and click on a link vs this method. Opera also offers nice shortcuts for moving around links in a page like ‘a’ and ‘q’. And just a host of other stuff. Plus it’s blazing fast. Not like firefox claims to be, no Opera is actually fast. And it doesn’t crash and hog memory like Firefox. At least most of the time. Sorry to go off on a tangent here, I don’t mean to bash Firefox as it actually has a great suite of plugins for web development, but for me Firefox is a web development platform only, not a browser.

3. Learn a scripting language. Bash, Perl, Ruby, Python. Pick one and learn it. I learned Perl (for some value of learn) when I was in high school because I thought it was really groovy to squeeze into one line an entire world of code that no one could understand. Then I tried to use Perl for everything including writing object oriented code, which may have been a mistake. Well, I grew out of that phase but I still use Perl on occasion (once every couple weeks) to automate things in my life. Since I’ve started to use Ruby last January, I’ve also been trying to force myself out of the Perl habit and to write some system scripts in Ruby, because at least the word Ruby doesn’t scare people off as much as Perl. The truth is, it’s still possible to write maintainable Perl code. Just use a lot of comments :)

To be functional in Perl you don’t need to understand hash ties or Perl OOP (in fact, I would advise you stay away from that. Bless self, wtf :)?, you just need to know how to do basic IO with files and the console, learn the power of Perl’s datastructures such as infinitely deep hashes (hashes of hashes of hashes malkovich malkovich), and you’ll be well on your way. But if I was to advise someone just starting today, I’d say start with Ruby because you’ll be learning not only a great scripting language but also a powerful and extremely high level object oriented and functional systems language that’s probably going to rule the world in a couple years, soon as we get a proper VM. Just you wait :)

4. Learn an editor. I mean a real editor. Both vi and emacs are acceptable choices here. TextMate is becoming a real option as well, although it still sucks at moving around the document which both vi and emacs excel at (imho vi is better at this, but maybe I don’t know emacs as well). The only real option in efficient text motion in TextMate is to do Ctrl+S (inline search), which is passable but leaves a lot to be desired. [Edit: I take that back, TM apparently has emacs style keybindings.]

My personal preference is vim but that’s because I’m ultra impatient, and I can’t wait even a second for my editor to start up. I gave emacs a good try, honestly for a month or two I tried to use it, and I could get used to this religion if only it had less overhead in starting up. Plus vi is available pretty much on any unix terminal so that’s also nice. Corollary: Use that editor everywhere. Now that you know vi, type set -o vi on your bash command line. Now use vi to edit your command line. Instantaneous productivity boost of about 10x. If you’re an Eclipse junky, use the Vi plugin for Eclipse.

If you learn one thing in vi: learn to move around using the home row keys, skip words using w, b and change commands such as cw (change word), or ctA (change from current position until the next occurrence of A). This becomes second nature because you look ahead as you type the command to achieve efficiency. There are plenty of tutorials, use google or the built in vi help system.

5. Learn regular expressions. There is no excuse not to know at least the basics. You don’t have to be a regex guru, just be functional. It probably takes a lifetime of meditation to achieve true regex enlightenment. But spending an hour a day trying to use regexes will take you 80% of the way. Read the perlre manpages, that’s where I got my start. Learn to use regexes in your editor to search, on your command line for quick one off scripts, in your programs to do text manipulation.

None of these things are hard, they just take practice and dedication to become true habits. The most important way to turn them into habits is to establish a routine that forces you to apply one or more of these principles and ideas every day.



Post a Comment

<< Home