Random ramblings

11.21.2005

How to Write Unmaintainable Code

A few of my favorites:
Extended ASCII
Extended ASCII characters are perfectly valid as variable names, including ß, Ð, and ñ characters.

Names From Mathematics

Choose variable names that masquerade as mathematical operators, e.g.:
openParen = (slash + asterix) / equals;

Hungarian Notation
Consider this real world example "a_crszkvc30LastNameCol". It took a team of maintenance engineers nearly 3 days to figure out that this whopper variable name described a const, reference, function argument that was holding information from a database column of type Varchar[30] named "LastName" which was part of the table's primary key. When properly combined with the principle that "all variables should be public" this technique has the power to render thousands of lines of source code obsolete instantly.

Choosing The Best Overload Operator
In C++, overload +,-,*,/ to do things totally unrelated to addition, subtraction etc. After all, if the Stroustroup can use the shift operator to do I/O, why should you not be equally creative? If you overload +, make sure you do it in a way that i = i + 5; has a totally different meaning from i += 5; Here is an example of elevating overloading operator obfuscation to a high art. Overload the '!' operator for a class, but have the overload have nothing to do with inverting or negating. Make it return an integer. Then, in order to get a logical value for it, you must use '! !'. However, this inverts the logic, so [drum roll] you must use '! ! !'. Don't confuse the ! operator, which returns a boolean 0 or 1, with the ~ bitwise logical negation operator.

Nesting

Nest as deeply as you can. Good coders can get up to 10 levels of ( ) on a single line and 20 { } in a single method. You earn extra Brownie points whenever the beginning and end of a block appear on separate pages in a printed listing. Wherever possible, convert nested ifs into nested [? ] ternaries. If they span several lines, so much the better.

Please do not take this seriously. It is a joke. Here's what I think (partly based on the experiences of my father, who is a software engineer): people who write unmaintainable code to ensure they keep their jobs are terrible to work with (that was the understatement of the day). If you don't put in the effort to be good programmer in order to keep your job, you don't deserve to have a job in the first place.

1 Comments:

Blogger Herb said...

And chances are if you follow this, either
1 - Your manager will rip your head off/can you when (s)he finds out

2 - You'll have to completely rework the code at a later date, and be kicking yourself in the pants for your earlier fun.

3:27 AM

 

Post a Comment

<< Home