It’s not because I’m OCD

Where possible, source code should be formatted to reflect the logical structure of the function or method.  Most folks are on board with that. (if you are programming in Python, it’s mandated!)

But within that constraint, I’ve noticed that I’m more prone than most to line up my source code by columns. For example:

a    = 1;
bb   = 2;
ccc  = 42;
dddd = 527;

rather than

a = 1;
bb = 2;
ccc = 42;
dddd = 527;

Or with a Clojure map:

(defn my-aligned-map
  {:a-key           "Okie"
   :another-key     "Dokie"
   :yet-another-key "Pokie})

…rather than

(defn my-aligned-map
  {:a-key "Okie"
   :another-key "Dokie"
   :yet-another-key "Pokie})

This is mediated by what makes the source easier to read. The approach breaks down if a preceding variable name is so long that the gap below it is hard to “bridge” by eye:

why_would_anyone_make_a_var_name_this_long = 100;
t                                          = 200;

I structure my code this because I like it. But there may be more to this than quirky taste: visual displays should prefer simplicity, and one measure of simplicity is the count of distinct x and y values for the positions of widgets, icons, and other controls or display items.   Vertically aligning items on related statements in your program applies this principle to the “display”  of source code.

And I thoroughly hate pretty-printers that discard my “excess” spaces.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s