Union  Union

go to home page feedback about the unmaintainable code essay full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish ©2000-2009 Roedy Green, Canadian Mind Products

Here is an email I received in response to my essay on how to write unmaintainable code.

Union : Dave Doolin : doolin@cs.utk.edu : 2000-11-06

I wish I could show you this one function I have…

It defines a union of char[4]; and uint, inititializes the int using a function call, then the argument to return is a huge single line of &&, ||, <<, >>, <, >, == etc. operators. The idea is to return a boolean value. The single comment is /* cool hack, gene */

Now, I don’t really have a problem with the union, nor the long gross return. The real heinousness is that all the test values are literals! Have a little typo accident with emacs, vi or msvc or whatever anywhere in that line, and you get a virtually untraceable bug! The code will compile and run just fine changing values or operators willy nilly! It will even work correctly most of the time!

There is of course, not test function written for this code. Even better, the author is now CEO at a startup…

Uh oh… boss just drove in…


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/feedback/unmain/union.html J:\mindprod\feedback\unmain\union.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
viewYour face IP:[38.107.191.100]
You are visitor number 11.