Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some advantages of type hinting:

- Editors and IDEs can use them to provide better autocompletion for you. That way you can discover how to use APIs while you write code without having to look at the docs all the time.

- Static analysers can tell you when you're making trivial errors just after you type them.

- They provide a form self documentation. In practice, most medium to large Python projects already add type signature information in the form of docstrings, using thing like '@param'. This is better because it's more uniform.

This is not against duck typing, you can use Abstract Base Classes to define an interface for some behaviour and match objects that provide that behaviour even if they don't belong to any specified type hierarchy.

Finally, this is completely optional. You can keep coding without types for your small scripts or private functions, while using type information for the APIs of big libraries.



- The interpreter/VM can use them to optimize some code to very fast equivalents or some data structures to very compact equivalents.


sounds like Cython. Are any such optimizations planned for 3.5 (or beyond)?


Not that I'm aware of. This type hinting is currently planned for analysis, not for efficiency.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: