PyWart: Language missing maximum constant of numeric types!
rantingrickjohnson at gmail.com
Fri Feb 24 10:25:21 EST 2012
On Feb 24, 8:25 am, Neil Cerutti <ne... at norwich.edu> wrote:
> > What Python needs is some constant that can be compared to ANY
> > numeric type and that constant will ALWAYS be larger!
> What's the point of that?
> The only time I've naively pined for such a thing is when
> misapplying C idioms for finding a minimum value.
The best use case is for default arguments to constructors or func/
meths. If you set the argument to INFINITY instead of -1 (or some
other dumb string value to mean "unlimited") you can omit a useless
conditional block later. Observe:
if maxlength == -1 # unlimited length:
elif len(object) < maxlength:
stop() # because we reached the limit
I see tons and tons of old Python code that uses -1 as an "unlimited"
value, where positive numbers are meant to constrain dome value. I
have always found that to be intuitive; hence my question.
More information about the Python-list