Clarity vs. code reuse/generality

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Jul 7 03:16:41 CEST 2009


On Mon, 06 Jul 2009 16:43:43 +0100, Tim Rowe wrote:

> 2009/7/4 kj <no.email at please.post>:
> 
>> Precisely.  As I've stated elsewhere, this is an internal helper
>> function, to be called only a few times under very well-specified
>> conditions.  The assert statements checks that these conditions are as
>> intended.  I.e. they are checks against the module writer's programming
>> errors.
> 
> Good for you. I'm convinced that you have used the assertion
> appropriately, and the fact that so many here are unable to see that
> looks to me like a good case for teaching the right use of assertions.
> For what it's worth, I read assertions at the beginning of a procedure
> as part of the specification of the procedure, and I use them there in
> order to document the procedure. An assertion in that position is for me
> a statement to the user of the procedure "it's your responsibility to
> make sure that you never call this procedure in such a way as to violate
> these conditions". They're part of a contract, as somebody (maybe you)
> pointed out.
> 
> As somebody who works in the safety-critical domain, it's refreshing to
> see somebody teaching students to think about the circumstances in which
> a procedure can legitimately be called. The hostility you've received to
> that idea is saddening, and indicative of why there's so much buggy
> software out there.

LOL.

Maybe the reason for "so much buggy software" is that people 
inappropriately use assert, thus changing the behaviour of code depending 
on whether it is run with the -O flag or not.

I don't know what "hostility" you're seeing. The only hostility I'm 
seeing is from the OP, which is bizarre considering that he asked for 
advice and we gave it. What I see is a bunch of people concerned that the 
OP is teaching novices a bad habit, namely, using assert for error 
checking. He claims -- angrily and over and over again -- that in his 
code, the assertions should never fail. Great. Good for him for knowing 
when to use assert. But are the novices going to learn that lesson, or 
will they simply learn "use assert for error checking"?



-- 
Steven



More information about the Python-list mailing list