Sometimes you’ll see (or write) code like this:
This show what I call “Tabular Alignment,” the insertion of horizontal white space to make certain elements of the code line up. It makes the code nicer to read, but it is costly to maintain.
Makes Editing a Chore
Editing code that is tabular aligned can be a chore. Suppose we are starting with this:
and need to add this:
Since the width of the left column has changed, we need to edit every line in the block in order to maintain the tabular alignment:
Who wants to work that hard?
Is Destroyed by Search/Replace
Search/Replace destroys tabular alignment. Given this:
Suppose we decide to rename
@metadata, so we
use a search/replace operation to do it. Now, we get this:
In order to preserve tabular alignment, we need to examine every line of code where a replacement was done to ensure that tabular alignment is maintained.
If the search/replace takes place in a mode that doesn’t have you review every replacement, you won’t even know that you’ve messed up some alignment. The usual result is that misaligned code.
Now that’s not pretty, is it?
Makes a Mess of Version Control History
When a block of tabularly alined code needs to be realigned, the version control system will treat each of those lines as having been modified:
Now suppose that in the mean time, in another branch, a programmer has added a new variable:
Merging that branch will fail:
wayne@mercury:/tmp/foo$ git merge add_kittens Auto-merging foo.rb CONFLICT (content): Merge conflict in foo.rb Automatic merge failed; fix conflicts and then commit the result.
Without tabular alignment, this merge would have succeeded automatically.
Why make more work for ourselves?