Friday, September 18, 2015

How to write unmaintainable code...

How to write unmaintainable code...  This is just what the world needs: a set of instructions for how to write code that is impossible for someone else to modify or fix.  It would be hilarious if it didn't sound so much like code I've actually worked on!

One example:
Wherever scope rules permit, reuse existing unrelated variable names. Similarly, use the same temporary variable for two unrelated purposes (purporting to save stack slots). For a fiendish variant, morph the variable, for example, assign a value to a variable at the top of a very long method, and then somewhere in the middle, change the meaning of the variable in a subtle way, such as converting it from a 0-based coordinate to a 1-based coordinate. Be certain not to document this change in meaning.
That is just plain evil.  But I've seen code like that, and been burned by it.

Sometimes I wonder if the Internet is actually a good thing...

No comments:

Post a Comment