[TIP] Column questions.

Pete pfein at pobox.com
Thu Jul 24 10:42:35 PDT 2008


On Jul 24, 2008, at 11:26 AM, Andrew Dalke wrote:

> Laura wrote:
>>    Not for me, instead it makes it a lot easier for me to modify
>>    my API.  But then I am a 'design your API last, or at least
>>    fairly close to the end of the process' sort of person.
>
> I'm more of an API first, although I can also be algorithm first,
> in order to figure out where good entry points are.

I'm almost always structure first (I don't think of it as an API, most  
of the time).  The process feels like continuous refactoring, as  
blocks move around, get lifted/pushed down, broken out and otherwise  
beaten into shape.  I usually go from a high-level design in my head  
to writing building-block objects and then working my way back up.

>      Another advantage is that test-driven development,
>      when used properly, ensures that all written code is
>      covered by a test.

Ha, really?  Do you write code until all your tests pass, and then  
back slowly away from the keyboard?

> I of course do make unit tests once things have firmed
> up a bit, and they've proved helpful.  But not early
> on when I'm still trying to figure out what the functions
> and classes do and what to name things.

Hmm, I tend to write formal unittests early on, though after I've  
named things & got the basic structure together.  The tests have  
largely replaced the muck around in the shell/debugger phase of  
development.  The tests are far more effective, as they repeatable and  
a lot more rigorous.  It's also makes the subsequent refactoring *way*  
faster.

It's interesting to hear all the different approaches people take.   
We're all on the same page that Testing is Good, but the how/when  
seems correlated with coding style. Maybe we should have a Approaches  
to Coding BoF/Panel at PyCon?  I feel like I could learn a lot from  
such a conversation - clearly TMTOWTDI, and having some more tools in  
the arsenal never hurts.

--Pete



More information about the testing-in-python mailing list