4 ms·
See http://www.python.org/dev/peps/pep-3107/ http://www.python.org/dev/peps/pep-3107/. Annotations provide a loosely organized way to introduce type checking t
by ak217 13y ago
See http://www.python.org/dev/peps/pep-3107/ http://www.python.org/dev/peps/pep-3107/.
Annotations provide a loosely organized way to introduce type checking to your inputs and outputs. They serve as built-in documentation and IDE hinting mechanism, but also provide the ability break early when the function's I/O contract is broken. IMO they are awesome and quite Pythonic.
- zanny 13y agoPersonal stylistic opinion here but while the concept of annoations is pythonic, I think the implementation we got is the opposite. It uses magic glyphs that require research to interpret - especially if you come from any other programming language, because when you see things like a : b, or foo -> bar, you expect that to have some syntactic meaning. The fact that the colon and right arrow in a Python annotation are, for the interpreter, a no-op, is insanely confusing to a newbie or just a generalist. It is compounded by how it would have made much more sense to reserve keywords in their places, so instead of def foo( a : "fruit", b : Color) -> Pineapple: you could have used reserved names: def foo( a expects "fruit", b expects Color) returns Pineapple: Which is a lot more readable in the way Python is meant to be. Good Python code reads more like prose than software, and the former prevents that from happening at all.
- Mizza 13y agoI agree completely! When I see a ':', I think slice syntax, and when I see a '->', I think.. hashrocket? What is this madness? Is anybody interested in working on a PEP about this?
- ak217 13y agoI agree with you. I think it was a mistake to use punctuation, and I like the keywords that you propose.
- aortega 13y agoThere are a lot of awesome things that can be added to a language. Python is nice because it's simple and intuitive and you don't really need to read the docs to figure out how to do things and use libraries. Now it's becoming more like C++, where each hotshot developer want to add his language extension to do some obscure thing nobody really uses except from them and their friends. It will be the demise of Python. What about this instead: make it faster.