Too early implementation

Patrick Mullen saluk64007 at gmail.com
Sat Apr 18 13:21:02 EDT 2009


2009/4/18 Filip Gruszczyński <gruszczy at gmail.com>:
> Yep, I have heard a lot about test driven development. I am now
> programming a lot using DJango and I would like to use its test
> framework to try it. However, I have little experience with this (as
> most people I know). I also have no idea, how to apply this, when I
> write code heavily focused on user interface.

There are many testing frameworks to choose from with regards to
interface, but at least starting with unit tests (which don't need to
interact with the interface) will still gain you something, and help
guide the design probably a little better than interface tests at
that.  My style of TDD is to alternate somewhat between the code and
the tests. When that idea pops into my head about how to do something,
I will either write a test OR write the code to make it work,
depending on what my inspiration is. If the inspiration is API
related, then the test gets written first, because what is in my head
are really interface stuff and not implementation. On the other hand,
if my inspiration is code/implementation related, I will write the
code. Afterward, I will switch and write the other piece, which sort
of backs up whatever my decision was (or doesn't).

I don't follow this exactly, it's just my general coding style when I
am using tests.

Sometimes I don't use tests at all (they aren't quite as helpful in
game programming as in other domains), and in those cases I generally
try to refactor or clean up my code before a script gets "too long",
where too long means I am getting frustrated at not being able to find
where to fix problems or add features fast enough. In practice, this
usually means writing about 800-1000 lines of code in one script, and
then exploding one script into several.

> I thought, that prototyping is cool, especially with python, where you
> can create something functional pretty quickly. But recently I was met
> with a situation, when after writing 1k lines of prototype and then
> writing main program > 3k lines I noticed, that there is something
> really wrong with the design. It was then, that I started wondering:
> maybe I should first prepare some good design documents, I don't know
> some SAD or something.
>

It's pretty hard to design very much up front, because when you get
into the code things change. Maybe if you do some coding and then
start designing as you go to keep yourself on the right track.



More information about the Python-list mailing list