Python is DOOMED! Again!

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jan 21 23:30:57 EST 2015


Occasionally you find people spreading Fear, Uncertainty, Doubt about 
Python. Python is now over 20 years old and one of the most popular 
languages in the world no matter how you measure popularity:

http://import-that.dreamwidth.org/1388.html

so you don't often get FUD these days. When you do, it's usually about 
whitespace, or "Python is too slow", or occasionally "Python 3 is killing 
Python", but the latest FUD is about PEP 484 and type-hinting:

https://www.python.org/dev/peps/pep-0484/

Here's a typical example:

    Python is already headed towards obscurity. ... it seems that 
    GvR intends to drive the final nail in python's coffin with 
    this "type hinting" crap that will convert Python syntax from 
    a readable pseudo code into a cryptic nightmare.

    Type hinting violates the very ESSENCE of what Python was
    meant to be, that is: a "clean and intuitive syntax". 


(Google for it if you care for the source.)

So what is this unspeakable, nightmarish, cryptic abomination going to look 
like? Here's an example from PEP 484:

def greeting(name: str) -> str:
    return 'Hello ' + name


I don't know about you, but I think anyone who cannot read that and intuit 
that argument `name` is a string and the return result is also a string is 
probably going to have bigger troubles with Python than just type-hinting.

Remember too that type-hinting will *absolutely* remain *completely* 
optional for Python. Developers can choose to use it or not, they can mix 
hinted code with regular unhinted code, they can use type declarations 
purely as documentation or they can run an optional type-checker, as they 
choose.

Here's a potential real-world example, from the statistics module in Python 
3.4, before and after adding annotations:

def median_grouped(data, interval=1): ...

def median_grouped(data:Iterable[Real], interval:Real=1)->Real: ...


I say "potential" because the standard library doesn't use annotations yet, 
but it may in the future. 

So how does Python's proposed type-hints compared to that used by other 
languages?

Java:

  public double median_grouped(List<Double> data, double interval) {}

Pascal:

  function median_grouped(data: IterableOfReal; interval: Real): Real;

C:

  double
  median_grouped (IterableOfReal data, double interval)

Haskell:

  median_grouped               :: [Double] Double -> Double
  median_grouped data interval =  ...


(I may have taken some very slight liberties with the syntax, corrections or 
more idiomatic forms are very welcome.)


I think it is clear that Python's annotation syntax remains quite close to 
executable pseudo-code. Fears that type-hints will doom Python are not 
credible.


-- 
Steve




More information about the Python-list mailing list