Vertically Aligning Code

Terence Eden has a post in which he argues that code should be vertically aligned. Doing so, he says, improves readability and makes the code easier to understand. As an example, he offers

int robert_age = 32;
int annalouise_age = 25;
int bob_age = 250;
int dorothy_age = 56;

versus

int robert_age     = 32;
int annalouise_age = 25;
int bob_age        = 250;
int dorothy_age    = 56;

as an example of improved readability.

Folks can differ as to whether readability really is improved but the arguments against vertical alignment boil down to

  • It can mess up diffs
  • We don’t have the tools to make it easy

In the comments, Helge mentions that

git diff -w

ignores white space thus solving the first problem. It also has the -b option that ignores white space changes. Even if you aren’t using git, GNU diff also has the -w and -b options that do the same thing.

The second problem is what interested me. I kept thinking, “Just use align-regexp and be done with it.” Most times you don’t even have to highlight the code—Emacs will do the right thing by itself. That’s when I remembered that not everyone uses Emacs. Too bad. Use whatever editor you like but don’t complain we don’t have the right tools to do alignment. We have them; some just choose not to use them.

If you want another view, here it is.

This entry was posted in Programming and tagged . Bookmark the permalink.