sajad torkamani

1. Red – make it fail

Write a little test that doesn’t work and that might not even compile at first (undefined class, method, etc).

2. Green – make it pass

Make the test go green as quickly as possible, committing whatever sins necessary in the process. You’ll make your life harder if you try to both (1) find a solution to the problem and (2) engineer the code right at the same time. You’ll either have an analysis-paralysis or you’ll over engineer the code.

Put your duct-tape programmer hat on and just get things to work. Copy code from StackOverflow, duplicate code, don’t worry at all about naming or formatting. Do whatever it takes just to make the test pass.

Be like this guy:

Just make the test pass.

3. Refactor – make it simple

Make small refactor. Rerun test. Make small refactor. Rerun test. Keep repeating until you think your code is sufficiently simple and performant.

Things you could do:

  • Reduce duplication.
  • Choose more descriptive names for your variables, methods, and classes.
  • Add comments if you think a bit of code may confuse you in the future.
  • Extract method (split long method, remove comments, shorten long parameter list).
  • Extract class.
  • Avoid clever code that tries to be overly flexible. Aim for very, very boring code.
  • Apply patterns (but be wary of being pattern happy).
Tagged: Misc