Wednesday, April 8, 2009

Reflections on Falling Blocks

There were various things I liked and didn't like about my code for Falling Blocks.

  • The code for block rotation and row removal. The board code got a little complicated (due to an experiment that I kept), but I had tests that made getting that code correct a quick process. I got this working first and really didn't have to touch it again.
  • The way the current 'screen' is implemented - just functions in the game state. (Two functions - one like an OO MVC 'controller' and one like a 'view'.)
  • Relatively short. Under 500 lines without tests/comments. Probably could be shorter.
Didn't like:
  • Testing was hard. It seemed like there was a lot of setup for a simple test. I ended up exposing more of a given module than I wanted to make sure that functions that were just used in the module were working correctly. In the end, I wrote far fewer tests than I would have liked. I think a lot of this boils down to not factoring my code well - still trying to figure out how do to that in Haskell.
  • Also, not sure how to only test 'part' of something. If A uses B which uses C - how to test A without needing to test the rest. I want to stub or mock the rest, but don't know how.
  • Some of the code got too complicated (for example, the 'move' method isn't pretty). For a lot of the code, I didn't feel like I was 'gluing simple functions together'.
Any suggestions on the code are more than welcome.

No comments:

Post a Comment