Alec Nevala-Lee

Thoughts on art, creativity, and the writing life.

The perils of coding cleverness

leave a comment »

Programming Proverbs

Every programmer has a secret desire to produce a truly clever program. Shortening the code by two lines, running the program two seconds faster, or using fewer identifiers are all popular pastimes. Resist this temptation, because the benefits seldom outweigh the hidden costs. Aside from the extra time needed to develop that “special wrinkle,” hand-checking and debugging tricky code is often a study in horror, and one must be extra careful of boundary conditions.

When tricks are indiscriminately employed, good structure, flexibility, and clarity are frequently lost. Merging two or more sections of code to wring out those “extra” lines is an easy method of preventing anyone from following your algorithm or extending your program. Before removing the extra lines, it might be worthwhile to remember that fewer lines of source code may not always result in fewer machine instructions…

In short, beware of “clever” code, and beware of being “penny wise” but “pound foolish.”

—Henry F. Ledgard, Programming Proverbs

Written by nevalalee

September 28, 2014 at 7:30 am

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 )

Google photo

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

Connecting to %s

%d bloggers like this: