Efficient Software Development – Part 1


I have been meaning to write something on this topic for a while. The motivation largely comes from the experience of working in a large company and getting work done amidst a mindless number of context switches. It kind of reminds me of the term “thrashing” where the CPU spends most of the time switching between tasks than doing the tasks themselves.

Slow development is a major pain point of every developer I would imagine. To reduce stress I have setup my own environment to minimize the time it takes to reload the brain with the context of the task at hand.

At work I primarily have to develop stuff that can used/tested/mucked-with in a browser so I primarily just need a shell and browser. My work laptop is a macbookpro so I am all set with Terminal, Firefox, Safari and Thunderbird. And Adium, ofcourse.

1. Screen
Regardless of whether the terminal supports tabs or not, screen is a must-have tool to group several shell sessions together. With a nifty .screenrc and a few memorized shortcuts, it is probably better than sliced bread. Whenever I start a new project, screen -S projectname will start a screen and it will exist till the end of the project. Using different tabs on the terminal it is cool to switch between different screen sessions. Here is my .screenrc:

# .screenrc

startup_message off
escape “

hardstatus alwayslastline
hardstatus string ‘%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'

screen 1
screen 2
screen 3
screen 4

2. Vim
I am a vim guy and I understand there is an equally strong crowd of emacs folks. I have been using vim since 1998 and every time I see someone straining with a text editor and mounted remote drive I feel really sorry about the pain. I am not going to list all the cool features of vim, but the most used setup is in my .vimrc as below. A big monitor can make using split screens a dream, even on a remote server and using vim in text mode (non gui).

# .vimrc

syntax on
set ai nu showmatch
set incsearch hlsearch ignorecase
set shiftwidth=2

"formatoptions extra to make big comment lines easier
set fo+=ro

"show the command as it is typed
set showcmd

"customized key mapping - v to comment, z to uncomment
:map v I// ^[
map z I<Del><Del><Del>^[<Right>

3. Aliases
I lost track of wasted time typing "tail -f /foo/blah/blah/yapache/error" in a remote box, so I made a list of aliases that I will actually remember to use. Before using a remote box, copy the .bashrc one time and be done with it. Some of mine:

# .bashrc

PS1="\u@\h \w \$ "

alias a='alias'
alias ls='ls -pF'
alias l='ls'
alias ll='ls -ltr'
alias rm='rm -i'
alias c='clear'
alias src='source ~/.bashrc'
alias xvi='gvim -rv'
alias f='find . -name'
alias cnu='cvs -n up 2>/dev/null'
alias cdi='cvs di 2>/dev/null'
alias pd='pushd'
alias ppd='popd'
alias ..='cd ..'
alias ...='cd ../..'
alias sls='screen -ls'

alias ht='cd /foo/blah/share/htdocs'
alias ta='tail -f /foo/blah/logs/yapache/access'
alias te='tail -f /foo/blah/logs/yapache/error'

4. ssh-agent
If you often ssh to remote boxes, then setup ssh-agent. Typing password multiple times in one terminal session is totally dumb.

First generate the public-private key pair using ssh-keygen.
Concat the public keys to ~/.ssh/authorized_keys and copy it to the remote box. Now do this:

$ eval `ssh-agent`
$ ssh-add

To be continued and/or edited...

  1. #1 by Dhyanesh on March 30, 2009 - 9:04 pm

    I have just loved screen ever since I started using it. It is like remote desktop for shells :) .

    I use it slightly differently though. I have only a single screen session. I always connect to this session and create new “buffers” in it. Basically in my .bashrc I have “screen -x” which automatically attaches me to the screen session. I have multiple terminals, each with one buffer of the screen.

    You should also try out Ion3 (http://modeemi.fi/~tuomov/ion/). It is a tiled and tabbed window manager with non-overlapping windows. You can navigate efficiently through all your open windows using the keyboard (with customizable keybindings). I swear by it!

(will not be published)