Wednesday, January 20, 2010

Easy version control - Why you should submit early and often

So the changelist that brought writing this post to mind was this one. I was working last weekend on Magecrawl, and decided that writing a "lightning bolt" like effect shouldn't be that hard. It just travels in a straight line until it hits a wall (or travels a maximum distance), hitting every creature in its way. In developing it, I violated a rule I try to follow in development both at home and work.
  • Each change should only do one things (Add feature, fix bug, fix performance issues)
  • Corollary: Submit each change independently as early as possible
It started off with the basic infrastructure for a new effect type, and then it ballooned into multiple different attempts of writing new subroutines to calculate the path of projectiles. After that, I didn't like the way it looked when drawn, so I refactored how we drew all ranged attacks on the screen. I also tacked on some unrelated preference settings, and some bug fixes.

The reason this was a problem was that things took twice as long as they would have if I was disciplined. Keeping changes small makes testing them before submission easier. It makes reviewing before submission easier (I review my changes for submission to keep myself from submitting lazy hacks). After each part, the lightning bolts still weren't right, and I got discouraged from hacking on them further.

Submitting early and often forces you to keep biting off small bits of the problem, fixing or implementing just that part, testing just that small part, and getting it submitted so you can work on another. I find that it works well for me.


    jice said...

    That's so true. I call this "microstep method". At the end of each day, the project must compile and run, whatever big refactoring you're into.
    While this may represent more work at the end, it ensure you'll never get stuck with a non compilable project that you will forget on a shelf.

    Jotaf said...

    I just installed mercurial/tortoise-hg and had a go with a small project. It's actually pretty fun! The red icons over the files indicate when there were changes so it's a good reminder. However, I can see this happening a lot, where you defer committing and then don't know what you did? Maybe it's just a matter of habit :)