Concealed Single-Letter Variable Names

The Trojan Horse
Timeo Danaos et data ferentes

While working on some old code of mine I was disappointed to find the following:

theta += omega * duration;
position = new Point(cos(theta), sin(theta));

Theta? Omega? What on earth was I thinking? Those are single-letter variable names. Single greek letter variable names. Spelling them out longhand doesn't change the fact.

I've seen the same pattern in other programs as well. Do we programmers suffer from terminal math envy? Do we think that only by writing unreadable tangles of greek symbols can we demonstrate our intellectual prowess? Even though we use the roman alphabet?

I wouldn't write code like this:

p += u*t + 0.5*a*t*t;

And writing it like this doesn't make it any better:

pea += ewe*tea + 0.5*eh*tea*tea;

This describes what is really being calculated:

position += velocity*duration + 0.5*acceleration*duration*duration;

And the first example is better as:

rotation += angularVelocity * duration;
position = new Point(cos(rotation), sin(rotation));

Copyright © 2005 Nat Pryce. Posted 2005-10-28. Share it.

Comments powered by Disqus