Communicating intent with your middle finger

Funny thing about the title is that you likely had a rather adult idea about what I meant.  The truth is, however, that the middle finger is just a symbol.  It’s not even that great of one either.  I might reasonably have nose-gold to mine, or I might be pointing at something, or maybe even itching something…or sometimes you are in fact #1.  An even more radical a concept is that in some cultures the middle finger means absolutely nothing at all.  So what did I mean?  It depends.

As contrived as the example might seem, this is how lots of people program.  There are both good and bad reasons for this.  A symbolic reference can make complex things easier to understand quickly.  The stop sign for instance, is easily recognized to mean STOP.  Even though it has the text on it, the visual alone is enough to derive the meaning (in our country).  The problem is that symbolic references only work if everyone knows what they mean.  This requires learning.  In some cases that is very fair.  In other cases it’s completely unreasonable.  For instance if I was a police officer, learning abbreviations for common types of crimes makes a great deal of sense.  I can respond rather quickly to a code-10.  However if I was working in a building and a guy ran around screaming -1!!!! -1!!! -1!!!!! -1!!!!!!!!… I would have no idea what was going on.  There has to be a valid justification to learning the symbol… otherwise it’s likely not worth it at all.

Status codes, abbreviations, and poorly named variables / methods can be exactly as obscure.

If you are working against a known set of quantities, why not make it an enum?  What do you lose by doing it?  Instead of passing around codes like: “RD”, “IT”, “TV”, I could write that as: MediaType { Radio, Internet, Television }.  Which one is easier to understand?  If there is a compelling reason that Radio must be RD… you can always explicitly set the default value.  If that is not always an option, why not write a translation table from the enum to the complex value type?  Now, the consumer of your code doesn’t need to be worried about the fact that Radio = RA, Internet = IT and so forth.  You keep the symbol, but you gain readability.  This doesn’t even begin to cover the painful process of keeping two pieces of code in sync with the same keys to communicate.  If an enum is missing, it’s generally far easier to catch.  Even better, have the service SEND the enum to the client.

Abbreviations are just as bad.  Recently in a project I had to get on a co-worker’s case about using MC as a namespace shortcut & as part of a class name.  The main issue in this case is readability.  I am still, to this day, confused by what MC is.  Not just because I forget easily, but because there are at least three other namespaces or services that are also legitimately called MC.  This actually becomes a more complex problem as you work in multiple places that each share the same abbreviations for things, but have entirely different meanings.  Your first expose to an abbreviation can greatly impact any future usage… even if it’s entirely different.  Working in retail for instance a POS is a point of sale… having worked in computers for a long time… it’s what I refer to my laptop as 🙂

Make sure you name your variables and methods with something that makes obvious sense.  I worked on a project a while ago where there was a function called VarifyArgs() that was overloaded to handle ints, objects, strings and longs.  What does it do?  I have no idea.  In this case it’s pretty obviously bad form.  But what about using T parameters in generic functions?  Complex generic factories are hard enough… why make them harder with variables like T and F?  How about TResult, TRequest? For that matter, why can’t “i” in a for loop be called count? Does the 4 extra characters really offend you so much?  If so, why not instead call it “index”?  Some of the reasons that we use these commonly short variable names are a legacy artifact.  The name of the variable itself consumed memory in the system.  In modern languages, that is not the case at all.  The compiler actually renames variables and even then, they are just pointers to what it means.

In short, your symbolic references are for you and your team alone.  If, for no other compelling reason, you will at one point forget what -1 meant.  Take steps to help your failing memory.  Your co-workers and future self will thank you.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: