In the course of studying biophysics using computer models, I spend a fair amount of time writing computer codes. One of the most important features of a useful code is its durability, and specifically, how easy it is to customize, reproduce, and duplicate.

Over time, I’ve found that the most durable codes have the least red text in them. Most text editors color strings and floats in a special color (red in vim, pink in gedit, green in sublime). These colors help you distinguish variables from constants. Here’s an example from an automacs extension module.

#!/usr/bin/env python

from amx import *

init()
make_step(settings.step)
write_mdp()
write_continue_script()
build_bilayer(name='vacuum-bilayer')
copy_file('vacuum-bilayer.gro','vacuum.gro')
state.force_field = state.force_field_upright
write_top('vacuum.top')
minimize('vacuum')
vacuum_pack_loop(
	structure='vacuum-minimized',
	tpr='em-vacuum-steep',
	gro='vacuum-packed')
restuff(
	structure='vacuum-packed',
	gro='solvate-dry',
	tpr=get_last('tpr'),
	ndx=get_last('ndx'))
solvate(
	structure='solvate-dry',
	gro='solvate-dense')
write_top('solvate.top')
minimize('solvate')
remove_jump(
	structure='solvate-minimized',
	tpr='em-solvate-steep',
	gro='solvate-nojump')
counterions('solvate-nojump','solvate')
counterion_renamer('counterions')
write_top('counterions.top')
minimize('counterions')
remove_jump(
	structure='counterions-minimized',
	tpr='em-counterions-steep',
	gro='counterions-nojump')
bilayer_middle(
	structure='counterions-nojump',
	gro='system')
bilayer_sorter(
	structure='system',
	ndx='system-groups')
state.force_field = settings.force_field
write_top('system.top')
equilibrate(groups='system-groups')

The telltale sign of an extensible code is the almost total lack of seemingly arbitrary strings or floats in the functions. These constants almost always require fine-tuning, membership in a parameter sweep, or further correction. A far-sighted programmer will remove these parameters to a settings file which can then be tuned, saved, and copied in an uncluttered way.

The code above is an example automacs procedure for creating a lipid bilayer. It does a fair job of removing all of the red parts, and wheverever possible, it uses standard names for the constants that remain. This particular procedure calls standardized functions which

To put it another way: the more we weave together the design with the tools, the harder it will be to debug, make changes, or extend the method to other use cases. This is only a design principle — code is infinitely malleable. The crucial bottleneck is typically the effort required to ask a new question. If the cost of further extensions is too high, then we might never use our old codes to test novel hypotheses. My claim that red-free codes are the most durable is just another way of saying that it is best to write modular codes. The more modular the code, the more interchangable and reusable it will be.

As a corollary, the best codes are also mostly bluish, that is, they contain a large number of concise, informative comments. The figure above has little red, but it could use far more comments if it hopes to stand the test of time.