Skip navigation

How to write Evil, Unstable code

How to write evil code? It’s easy, follow the guidelines. :)

Conditional Slalom - Always, always, feel good when writing lengthy if branches and switch statements. These increase the number of possible execution paths that tests will need to cover when exercising the code under test. The higher the Cyclomatic complexity, the harder it is to test! When someone suggests to use polymorphism instead of conditionals, laugh at their thoughtfulness towards testing. Make the branching both deep and wide: if you’re not consistently at least 5 conditionals deep, you’re spoon feeding testable code to the TDD zealots

Use More Statics - Statics are a really powerful tool to bring TDD Infected engineers to their knees. Static methods can’t be overridden in a subclass (sometimes subclassing a class and overriding methods is a technique for testing). When you use static methods, they can’t be mocked using mocking libraries (nixing another trick up the pro-testing engineer’s sleeve).

Use static initializes - Do as much work as possible when your class is loaded. Testing nuts will be so frustrated when they find out just loading your class causes nasty stuff like network or file access.

There is more following the link. It’s worth reading. I like that blog!

2 Comments

  1. Posted July 25, 2008 at 1:15 pm | Permalink

    Those guys are also creating posters for bathrooms in Google offices: http://googletesting.blogspot.com/2007/01/introducing-testing-on-toilet.html

    See the sample: http://code.google.com/testing/TotT-2007-02-01.pdf

  2. Posted July 27, 2008 at 8:44 pm | Permalink

    This remembers me old and funny
    “How To Write Unmaintainable Code”
    http://freeworld.thc.org/root/phun/unmaintain.html


Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*