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

Terry Reedy tjreedy at udel.edu
Wed Feb 21 00:18:47 EST 2018


On 2/20/2018 8:38 AM, Antoon Pardon wrote:

> People praise the dynamic nature of Python here on this list and then
> often enough seem to recoil when they see a piece of code really using
> that dynamism.

Dynamic typing is the addition of run-time type information (RTTI) to 
data values.  This allows duck typing of function parameters and 
function code.  Every function that uses duck typing, which is to say, 
most functions written in Python, is 'really using that dynamism' as 
intended.  The concrete type of arguments may change with every call, 
but the function code uses run-time type dispatch to get type-specific 
versions of the operations needed.

For instance, builtin min has a single parameter whose abstract argument 
type is "iterable of '<'-compatible objects".  It's code somewhere 
compares current_min < next_item, which dispatches to current_min.__lt__ 
or possibly next_item.__ge__.  Combining "list of | tuple of | set of | 
frozenset of | iterable of | dict keyed with" witn "ints | doubles | 
strings | bytes | '<'-compatible lists | '<'-compatible tuples" gives 36 
possible concrete input types.  "array of x" gives an indefinite number 
more, as does user additions.  I really like that we do not have to 
define a 'min_collection_type' function for every combination we might 
want to use in a package.

When makes people recoil is abusing dynamism by needlessly rebinding a 
name to objects of different specific type within a single block of code.

-- 
Terry Jan Reedy




More information about the Python-list mailing list