2008-03-10

10 ways to improve your code

A summary of Neil Ford's Software Development West 2008 "advanced code hygiene" presentation, 10 Ways to Improve Your Code, aimed originally at Java programmers, but with wisdom for coders of many [or any!] stripes. (Ford is a senior application architect and "meme wrangler" at ThoughtWorks, an IT consultant that specializes in development and delivery of software, and that is home to object-oriented development, refactoring and agile authority Martin Fowler.) From Reg Developer:
  1. Write the tests before writing the code.
  2. Use static analysis tools.
  3. Practice "good citizenship" by paying attention to how well your objects interact with the outside world. "Never let them exist in an invalid state."
  4. Avoid indulging in speculative software development. "The goal should be to build the simplest thing we need right now."
  5. Simplify essential complexity and kill accidental complexity.
  6. Challenge programming conventions, such as writing long, unreadable test names, and blindly following the JavaBean specification to the detriment of your code.
  7. Embrace single level of abstraction principle (SLAP). From Kent Beck's book Smalltalk Best Practices and Patterns: every public method should be as short as possible, and should consist of steps, each one of which is a private method. "Don't make abstraction leaps in your code."
  8. Leverage existing platforms with languages targeted at specific problems and applications.
  9. Learn every nuance of the languages you're using.
  10. Change your perspective and consider "antiobjects." An antiobject is a kind of object that appears to do the opposite of what we think it should do. The object metaphor sometimes impedes the solution "by making us try to create objects that are too inspired by the real world."

No comments: