Are the critiques in "All the things I hate about Python" valid?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Feb 18 23:32:04 EST 2018


On Mon, 19 Feb 2018 02:14:26 +0000, bartc wrote:

> On 19/02/2018 00:09, Steven D'Aprano wrote:
> 
>> Sure, but only the most boring, uninteresting kinds of types can be so
>> named. The point is that "sufficiently fine-grained types" can be
>> arbitrarily complex.
> 
> I don't think so.

That's nice. Do you have any reasons for your position?


>> If a human finds it hard to give it a meaningful
>> name, no algorithm will do it either. Consider:
>> 
>> "positive odd integers greater than 10 but less than 15003 divisible by
>> 17 except for 850, 867 and 1394; or primes that aren't Mersenne
>> primes".
> 
> Is that a type? Or a function? Or a set? Or a constraint?

It *could* be a type, if your type system was sufficiently flexible to 
allow you to specify something in that level of detail. Of course no 
existing type system is.

Which is of course my point: why static typing zealots do like to make 
grandiose claims about "sufficiently fine-grained types", the reality is 
that no type system is, or can be, sufficiently fine-grained to avoid all 
runtime validation.


> How would even a type for the odd numbers from 1 to 10 inclusive work?

That's an easy one: even Pascal in the 1970s could deal with enumerated 
types like the values 1, 3, 5, 7, 9. (I think.) So that's something that 
a type checker could easily verify at compile time. Given:

declare x, y : OddIntBetweenOneAndTen;

then:

x := 3

would be allowed, but:

y := x + 2

probably would be rejected, because the compiler may not be able to tell 
whether or not x + 2 is still an OddIntBetweenOneAndTen (unless it is 
actually tracking the value of x, which type checkers don't normally do).

Of course this put *severe* limitations on what you can do with such 
highly restrictive types, which is also part of my point.


> (That, a type consisting of one of the values in {1,3,5,7,9}.) Would
> they be ordered or unordered? Can I do arithmetic with them: will 3*3
> work, but not 3*5?

Operations on types do not necessarily have to return their same type. 
There's nothing wrong with saying that Odd plus Odd returns Even.



-- 
Steve




More information about the Python-list mailing list