PBP: 015 Vertical Alignment

The Perl Best Practices suggest to align things vertically.  They like to apace things out into neat rows of equals, fat commas, braces, and parenthesis.  Columns of data, when it will fit, are also approved of.

Honestly, I’m not so hot on this.  I find big blocks of assignments formatted like this to be strange, and I think doing it is an exercise in tedium.  Left to my own devices, I won’t do it, not because I find it a horror, but because it never ever occurs to me.

If I have a tool to do it, I might push the button to format stuff right, and won’t cringe when someone asks for it to be cleaned up in code review.

One of the things the book suggests is to align stuff into columns.  The example it gives is this:

my @months = qw(
    January    February   March
    April      May        June
    July       August     September
    October    November   December

(Please see the book or your favorite editor and perltidy for a proper example; this blog software is making formatting properly difficult.)

For months, this might be okay.  I’ve had other data sets where I found it absolutely miserable and it turns a list of things into a giant, confusing block of junk.  Perl still liked it, but it was unreadable and unmaintainable.  Single items on lines can be much clearer.

So, sometimes this is okay, and sometimes it’s ugly.  It’s never that important to me, personally.


Leave a Reply