[TIP] Doctest or unitest?

Michael Foord fuzzyman at voidspace.org.uk
Mon Mar 5 06:30:26 PST 2007


Andrew Bennetts wrote:
> Jim Fulton wrote:
> [...]
>   
>> potentially a lot harder.  When you read normal code, the intent of  
>> the code is usually known.  With tests, the intent is far less  
>> obvious.  I find that doctests tend to make test code more  
>> understandable because:
>>     
>
> I find even normal code can have extremely obscure intent.  The "how" is always
> obvious (that's what code is), but the intent needs explicit care from the
> author if it is to be communicated to the next person to look at the code.  Good
> habits in naming of identifiers and the like obviously go some way to helping
> here, so that taking this care becomes somewhat automatic, but it needs to be
> taken.
>
>   

I actually disagree with this fairly strongly.

I think good, well written code *can* communicate intent.

This is part of the point about 'DSL's. We have the flexibility in 
dynamic languages to write code that communicates as well as performing 
a function.

(For example) At Resolver our policy is to comment code as little as 
possible - if you can't work out the intent of code then it is badly 
written. Only in particularly obscure parts of the code (i.e. almost 
everywhere we interact with win32 stuff!) do we comment.

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml




More information about the testing-in-python mailing list