Strict typing is the way
Type hints are cool. Runtime enforced type hints are cooler.
Oh my gosh... This project and its readme are amazing. I gotta try this at work tomorrow, I hope my co-workers can bear with me.
Edit: I just found the release notes... I love it
Thanks for this. I might start to use this. This would allow me to add typing class or function at a time and slowly work my way back.
I had a mixed experience adding types to a large enterprise Python codebase.
I think the thing that really kills it is the (relative) lack of community support. Whereas with TS, almost every package big or small usually has types, I've found a lot of pip packages wouldn't be typed out of the box, which means you gotta generate them automatically or use escape hatches like Any.
Using escape hatches like Any basically kill the point of typing, as the static checker basically stops checking after it sees an Any. If your static checker is configured to ignore certain files because they aren't typed yet, then any code that refers to those files also get ignored. You basically need to hit a threshold of your codebase and dependencies to get the benefits of typing. Until then, my experience was finding bugs that the type checker should've caught but didn't.
And obviously, to get the full power of types, you must buy in as a team, and that means really buy-in, without resorting to escape hatches like Any. Any reluctance, and you're likely in for an uphill battle.
Another thing that really hurt adoption, was that before using typing, a lot of the code just clearly broke type rules, eg a function that returns a string or a number, but the caller assumes the output is a number. Especially if it's lower level code, those may take a nontrivial refactor to fix.
All of this is assuming it's trivial to enforce a static check on the codebase through CI/CD.
This leads to my conclusion, that not being forced to use types is a BENEFIT of Python, not a downside. You are able to write code a lot faster and more expressively if you don't need to worry about typing, for small scripts or whatnot. I think if you're starting a project of any size and already know you want typing, consider using another language that has typing built in.
I fully agree with the post. Except for a fast prototyping or a short personal script where it could be not necessary, type hint is a must. The subject is not only to guarantee that the program now runs without errors, but it will be still working right in the future too, even after a developer (either the original or other) make changes to the code.
I do type hinting everywhere, cause I like it when my IDE auto complete works well ❤️
My main issue is that you’re going through all that trouble and still get Python-level performance.
I really like Python, but there are better typed languages out there. Also, faster ones.
How true is that still? I know python 3.2/3.4/3.6 there were significant performance issues on simple pieces of code. But python 3.9/3.11 have been significantly faster. I imagine I could write faster C++ code, but I definitely couldn't write it nearly as fast or nearly as readable.
Python has gotten faster, but it’s still nowhere near what you expect from traditional compiled languages. It can’t be.
The trick to writing performant Python code is to get good (native) libraries and let it handle the heavy lifting.
For performance sensitive stuff, the fact that pure Python is very slow really matters. For stuff that’s not performance sensitive (that is, 99% of the code out there) it doesn’t really matter, but even then it’s better to be fast than to be slow.
Now this is not something I would ordinarily have a problem with. I use Python for a reason and it’s not performance. But if I end up writing Python like it’s rust, I might as well do rust and reap the (massive!!!) performance and memory profile benefits too while I’m at it.
Python3.10 was ~27x slower than Compiled C++ in this benchmark. Python 3.11 dropped that down to 17x just out of the box. Additionally, you can always write a python module in C or C++ to get the benefits of compilation. With the maintainability and flexibility of python.
Yeah using a dynamically typed language and trying to force strong/static typing seems like a waste of effort.
There are plenty around.
Python
Welcome to the Python community on the programming.dev Lemmy instance!
📅 Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django 💬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
🐍 Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
💓 Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
✨ Python Ecosystem:
🌌 Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythörhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API