PBP: 030 Ambiguous Abbreviations

This boils down to “don’t abbreviate when it isn’t clear.”  The response to this should be, “Well, duh!”

I do like that the PBP suggests that the “standard” single letter iterator variables (which it names as i, j, k, n, x, y, and z) are acceptable in loops.  I agree with this; if you’re just buzzing through an array quickly you probably don’t need a complicated name to tell you that this is the array element you’re looking at.  Especially if the loop fits entirely on a sensible sized screen!  (And if it doesn’t, maybe it’s too long.)

Sometimes this is harder to do than it sounds, because what is one person’s obvious abbreviation isn’t clear to another.  Is “temp” a “temporary” thing or a “temperature”?  Depends on what you’ve been working with lately, and the context you’re in.

Aim for clarity over brevity.

 

Leave a Reply