PyWart: Language missing maximum constant of numeric types!

alex23 wuwei23 at gmail.com
Mon Feb 27 07:49:27 CET 2012


On Feb 27, 1:51 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> Ints and floats can be compared directly, no need to convert the int to a
> float first

Ah, cheers. You can see how often I use the two interchangeably :)

> > Please provide a non-contrived use case of an "infinite string".
>
> Any lazy stream of characters that potentially goes on forever could be
> considered an infinite string. But that's not what Rick is talking about.
>
> He's talking about having a pair of special values, say, BIGGEST and
> SMALLEST, which compare larger and smaller to any other value, regardless
> of type and including strings, not literally a string with an infinite
> number of characters.

Yeah, my point was more to highlight Rick's laziness in co-opting a
defined term - INFINITE - and trying to use it to mean something else
that he couldn't express clearly. His original post stressed numeric
comparison, the feature creep to include all other types happened
later. Not the sort of thing we've come to expect from the resident
linguist extraordinaire :)

> I can see some value for this as a convenience, but not enough to make it
> a built-in language feature.

For me, it feels like a step backwards to comparing different types:

	>>> 1 < INFINITE
	True
	>>> 'string' < INFINITE
	True
	>>> 1 < 'string'
	Traceback (most recent call last):
	  File "<stdin>", line 1, in <module>
	TypeError: unorderable types: int() < str()

> Every developer should have at least one
> utility module with all the trivial code snippets they frequently use.
> This belongs in there.

Agreed. Especially when it's so trivial:

	class Bound(object):
		def __init__(self, value=None, always_greater=False):
			self.value = value
			self.always_greater = always_greater

		def __cmp__(self, other):
			return True if self.always_greater else self.value.__cmp__(other)

	>>> upper = Bound(100)
	>>> 101 > upper
	True
	>>> 101 < upper
	False
	>>> infinite = Bound(always_greater=True)
	>>> 101 > infinite
	False
	>>> 101 < infinite
	True
	>>> upper < 101 < infinite
	True



More information about the Python-list mailing list