Cool post, I've also been using more and more type hints and it really makes writing python more enjoyable. Although unfortunately it's still quite common for libraries to not have type stubs. On the section of construction functions, I've always used/seen `@classmethod` instead of `@staticmethod`. I just had a quick look at some big python libraries (pandas, transformers), and they do use class methods. Is there any…
Writing Python like it's Rust
41–50 of 369 posts
Re: Writing Python like it's Rust
#42> Is records a list, a dict or a database connection? Records is a list of record items. It’s a plural. If it was a dict, it would be recordByID. If it was a database connection it would be called connection. Strict typing is good, and you should definitely use it, but you should still have good names.
>If it was a dict, it would be recordByID. Never have I ever encountered any codebase where dictionaries were so named.
Re: Writing Python like it's Rust
#43It was better, but it _feels_ like lipstick on a pig. I love Python, but types are not what it's best at. It's missing features that makes typing easier.
I've realized if was going to write typed Python, I might as well switch to one that has better support for that and switched to .NET.
I can do almost all the dynamics things that I can do in Python with C#, but in a type safe way. Expressions and extension methods, reflection with `nameOf` opens up a lot of possibilities.
One thing that kept me using Python was SqlAlchemy, an ORM, a damn good one. Entity Framework Core, after V6 is a better one, especially with LINQ.
If you have the opportunity, give it a try. You might be surprised.
Re: Writing Python like it's Rust
#44> Is records a list, a dict or a database connection? Records is a list of record items. It’s a plural. If it was a dict, it would be recordByID. If it was a database connection it would be called connection. Strict typing is good, and you should definitely use it, but you should still have good names.
> Strict typing is good, and you should definitely use it, but you should still have good names. Linters and type checkers will understand type hints. They won’t understand your naming conventions.
Re: Writing Python like it's Rust
#45Tooling has come a long way in the past few years to help support better Python. Nowadays I can just throw on Pydantic V2 (still in Alpha, but stable to code against for basic use cases), ruff and mypy. Turn strict mode on in mypy and install the relevant vscode extensions and you get an experience that rivals a compiled language in both speed and usability.
What do you do when your dependencies don't have types? Also, with speed do you mean compilation or runtime?
Re: Writing Python like it's Rust
#46Earlier quoted context omitted.
Languages that you would build serious production software in, rather than some script. C, C++ are the main ones.
Lots of production software is written in Python, for better or for worse. In fact, production software gets written in every language eventually, no matter the intent of its designers. Maybe you only write your production software in C and C++, in which case good for you.
It takes a lot of effort to make a Python program not break on some inputs, so it's not really fire and forget like it is with C++. It's possible but it requires many more iterations.
Re: Writing Python like it's Rust
#47I started my programming journey with C# which is a statically typed language, and when I later was introduced to Python when I was in college, I really liked how convenient it is but the lack of typing made me really uncomfortable.
Re: Writing Python like it's Rust
#48Earlier quoted context omitted.
Languages that you would build serious production software in, rather than some script. C, C++ are the main ones.
So you deny that the industry used Python to build serious production softwares? Understood, no need to argue then, I don't think any amount of proof would change your mind...
You know the rule, 99% of everything is crud.
Re: Writing Python like it's Rust
#49Using a tool like Rust (or other strict/strongly-typed languages) forces some quality constraints on all code that compiles. This is, to me, a great benefit of these languages.