3 ms·
Rust is also poison for the mind. Sweet, sweet poison. I’m currently back to Python and losing my mind about doing error handling, as well as enforcing correct
by diarrhea 3y ago
Rust is also poison for the mind. Sweet, sweet poison.
I’m currently back to Python and losing my mind about doing error handling, as well as enforcing correct usage of my library API on the call site. Doing these things well (best?) in Rust is baked into that language’s DNA (Result, Option, newtype pattern, type state pattern, …). It’s painful to go without once you’ve seen the light.
- barelysapient 3y agoUsing Pydantic and the `validate_arguments` decorator can get you a lot more safety. Not as safe as Rust, but more safe than vanilla Python.
- diarrhea 3y agoI love pydantic and use it whenever I can, but that decorator seems a bit misguided, no? It requires type hints anyway, by which point mypy would catch issues with types mismatches statically, before runtime. That would seem strictly more useful. Maybe I’m missing an aspect of what the decorator solves though.
- barelysapient 3y agoMypy is an amazing, should have mentioned it. Pydantic enforces types when you're working with a Pydantic objects. However, it doesn't help with functions that accept vanilla types as parameters. validate arguments checks that the callers parameters matches the function's type hints. This is helpful because a static analyzer like mypy won't catch the wrong type being passed in all situations.