[Python-Dev] Type hints -- a mediocre programmer's reaction (original) (raw)
Ronan Lamy ronan.lamy at gmail.com
Fri Apr 24 19:27:29 CEST 2015
- Previous message (by thread): [Python-Dev] Type hints -- a mediocre programmer's reaction
- Next message (by thread): [Python-Dev] Type hints -- a mediocre programmer's reaction
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Le 23/04/15 14:55, Paul Sokolovsky a écrit :
Hello,
On Thu, 23 Apr 2015 09:15:44 -0400 Daniel Holth <dholth at gmail.com> wrote: []
Also ask why no one used type specifier, they are possible since Python 3.0 ? Because it is the wrong way for Python.
That's an example of how perceptions differ. In my list, everyone(*) uses them - MyPy, MicroPython, etc. Even more should use them (any JIT module, which are many), but sit in the bushes, waiting for a kick, like PEP484 provides. It's OK that type hints are only to assist the programmer. Yes, it's OK to have a situation where type hints assist only a programmer. It's not OK to think that type hints may be useful only for programmer, instead of bunch more purposes, several of which were already shown in the long previous discussion. PyPy's FAQ has an explanation of why type hints are not for performance. http://pypy.readthedocs.org/en/latest/faq.html#would-type-annotations-help-pypy-s-performance You probably intended to write "why type hints are not for PyPy's performance". There're many other language implementations and modules for which it may be useful, please don't limit your imagination by a single case.
Those points apply to basically any compliant implementation of Python relying on speculative optimisation. Python is simply too dynamic for PEP484-style hints to provide any useful performance improvement targets.
And speaking of PyPy, it really should think how to improve its performance - not of generated programs, but of generation itself. If compilation of a trivial program on a pumpy hardware takes 5 minutes and gigabytes of RAM and diskspace, few people will use it for other purposes beyond curiosity. There's something very un-Pythonic in waiting 5 mins just to run 10-line script. Type hints can help here too ;-) (by not wasting resources propagating types thru the same old standard library for example).
Sorry, but that's nonsense. PyPy would be a seriously useless interpreter if running a 10-line script required such a lengthy compilation, so, obviously, that's not what happens.
You seem to misunderstand what PyPy is: it's an interpreter with a just-in-time compiler, not a static compiler. It doesn't generate programs in any meaningful sense. Instead, it interprets the program, and when it detects a hot code path, it compiles it to machine code based on the precise types it sees. No resources are wasted on code that isn't actually executed.
- Previous message (by thread): [Python-Dev] Type hints -- a mediocre programmer's reaction
- Next message (by thread): [Python-Dev] Type hints -- a mediocre programmer's reaction
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]