Bounds checking

Martin De Kauwe mdekauwe at gmail.com
Sun Mar 20 06:24:04 EDT 2011


On Mar 19, 8:40 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> 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

OK I take your point and can see the superior logic! I shall amend
what I was planning



More information about the Python-list mailing list