Strong typing implementation for Python

Steven D'Aprano steve at pearwood.info
Mon Oct 12 20:07:36 EDT 2015


On Tue, 13 Oct 2015 04:20 am, Marko Rauhamaa wrote:

> As for managing complexity, many people believe static typing is a
> crucial tool. I disagree. Static typing adds vast amounts of noise to
> the code.

Only if you are stuck in the 1970s. And even then, it is not always noise,
type declarations or annotations often make useful documentation.

Consider the following piece of code:

def addone(x):
    return x + 1


The human programmer reading that can trivially infer that x must be a
number (or at least something which supports numeric addition). So can the
compiler. In a strongly typed language with no numeric promotion, the
compiler can infer that x must be an int. In a language with numeric
promotion, it can infer that x must be an int or float.

Where is the "vast amounts of noise" added to the code?



-- 
Steven




More information about the Python-list mailing list