Bounds checking

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Mar 19 05:40:42 EDT 2011


On Sat, 19 Mar 2011 01:38:10 -0700, Martin De Kauwe wrote:

>> Why don't you do the range check *before* storing it in state? That way
>> you can identify the calculation that was wrong, instead of merely
>> noticing that at some point some unknown calculation went wrong.
> 
> I guess no reason really. I suppose in my mind I was thinking it was an
> unlikely safeguard but I liked the idea of adding so would just do it at
> the end of a time step. In reality I think there is practically no
> difference and this way it is done once, in a single location vs.
> potential 10 separate checks? I don't see the advantage?

You should always aim to fail as close as possible to the source of the 
error as is practical. That decreases the amount of debugging required 
when something fails: instead of searching your entire program, you only 
have to search a very small amount of code.



-- 
Steven



More information about the Python-list mailing list