Is this a good idea or a waste of time?

Antoon Pardon apardon at forel.vub.ac.be
Mon Aug 28 17:29:55 EDT 2006


On 2006-08-28, Scott David Daniels <scott.daniels at acm.org> wrote:
> Antoon Pardon wrote:
>> On 2006-08-25, Simon Forman <rogue_pedro at yahoo.com> wrote:
>>> ...
>>> Generally asserts should be used to "enforce" invariants of your code
>>> (as opposed to typechecking), or to check certain things while
>>> debugging.
>> 
>> I don't understand this argument. Can't type checking be seen as
>> enforcing a code invariant?
>> 
> But it is practically never the "right" invariant.

And who decides what is and what is not the "right" invariant?

> You don't usually
> mean type(x) == int, but rather something like x is a prime between 2
> and 923.  Or 5< x**4 < 429, or _something_ problem specific.  saying
> that x must be an int is almost always simultaneously too specific and
> too general.

There seem to be enough problems that work with ints but not with
floats. In such a case enforcing that the number you work with
is indeed an int seems fully appropiate.

-- 
Antoon Pardon



More information about the Python-list mailing list