Tarek Ziadé’s Post

View profile for Tarek Ziadé, graphic

Author, Developer

It’s interesting to see some devs in the community finding that type annotations in Python improves code readability. For me it’s the other way around. I find annotated code much harder to read and unless annotations are used for a specific goal (mypy etc) I find that carefully named classes, methods, functions, arguments and variable are the best way to self-document Python code. So for me, if there’s a need for speed that pushed devs to add type annotations, maybe that’s when they need to switch to a language like Rust. If not, ´regular’ plain Python is just fine imho. #opinion

Meanwhile our 100+ million line Python code base with a significant portion of things statically analyzed by pytype and most recent code authors including annotations by default continues to prevent bugs and make it easier to maintain the code. Data from practical experience disagrees with your opinion.

Quazi Nafiul Islam

Software Engineer | Developer Advocate

1y

Would you like an editor feature that hides type annotations if you want it to? I think that could be an interesting feature.

Like
Reply
Marc-André Lemburg

CEO eGenix.com | Python, FinTech and Open Source Expert | Available as Consulting CTO, Senior Solution Architect, Consultant, Speaker and Coach

1y

Type annotations are great for things like data classes or models, but I'm not convinced that making Python look like C, TypeScript, Rust or Go is good approach. You get all the added syntax, but without the added performance benefits. For strongly typed Python, it's probably better to write Cython :-)

Hamza SENHAJI RHAZI

Devops Tech Lead for a DBA team chez BNP Paribas CIB

1y

It pleases the ears (or should say the eyes since it's a post) to hear that, I have seen some context where people enforce type annotations with the argument of "quality", but the truth is, other problems were hidden , like misnaming objects, complicated spaghetti code, not using POO when it was necessary (by the way, classes well named might serve a type like purpose) etc.. etc ..

David Teller

Software Tech Lead, Open Source Mentor, Mozilla Alumnus, Rust Contributor, Science & Data-oriented

1y

I have the opposite view. Even in OCaml (which is fully statically typed, but also has full type inference, so doesn't require type annotations), I found that adding type annotations was a considerable boon to documentation. In Python, I find that it decreases ambiguity and makes the invariants more explicit. Of course, I'm also of the opinion that mypy should be much more opinionated and stricter, which I suspect makes me part of another minority :)

Dean Ellis

Customer Support and Success Force Multiplier

1y

I have to say I miss the principled days of yore when python cared about things like, "There should be one, and preferably only one, obvious way to do it", or "Simple is better than complex", or "Complex is better than complicated", or "Readability counts", or etc. The language design is drifting.

I'm part of this choir, too. For me, Python type annotations obfuscate the code with noise. If I wanted the benefits of static typing, I would choose a language that has it properly built in. I suppose that cements my reputation for heresy.

Lennart Regebro

Opinionated Software Engineer

1y

I find it nice to make schemas. But I agree, it makes it less readable. I'm not convinced the mypy benefit outweighs the extra work.

The rubyists at Shopify have similar opinions: the code should explain everything. Comments are all but forbidden. Having been immersed in the typescript world myself, I prefer to understand the whole picture through types. I want to see the shape of everything. Pressing f12 in VSCode answers any question I have about how anything works and I love it. Large systems are complex and messy.

See more comments

To view or add a comment, sign in

Explore topics