Is this a good idea or a waste of time?
Scott David Daniels
scott.daniels at acm.org
Mon Aug 28 13:36:49 EDT 2006
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. 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.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list