(no title)
aomix
|
10 months ago
I saw someone describe python as “stressful” for this reason and I couldn’t agree more. It’s difficult to have confidence in any change I make or review. I need to sit down and manually exercise codepaths because I don’t get the guarantees I crave from the language or tooling. While with the small amount of Rust code I’ve written lately I could yolo changes into production with no stress.
pnathan|10 months ago
I have, roughly, sworn off dynamic languages at this point. Although I have dreams of implementing a firm typed system over Common Lisp.
shermantanktop|10 months ago
felipeccastro|10 months ago
(I know Python type checks aren’t mandatory, but for this question assume that the type checker is running in CI)
-__---____-ZXyw|10 months ago
unknown|10 months ago
[deleted]
jlarocco|10 months ago
Isn't that exactly what unit tests are for?
pansa2|10 months ago
I personally believe it's a valid argument (others will disagree). IMO the main benefit of static types isn't for correctness (nor performance) - it's to force programmers to write a minimal level of documentation, and to support IDE features such as autocomplete and red underlines. Hence the popularity of Python type hints and TypeScript, which provide these features but don't fully prove correctness nor provide any performance benefit.
mkehrt|10 months ago
airstrike|10 months ago
je42|10 months ago
d0mine|10 months ago
MrJohz|10 months ago
In this regard, Rust (and other languages where lots of data invariants can be encoded in the type system) is very flexible and easy to maintain indeed, because you can easily make changes, even in very old or poorly-maintained code, without having to worry about the consequences. Moreover, rather than writing all the unit tests yourself, it's as if the compiler is writing the unit tests for you.
In fairness, you can't encode everything in the type system, so you still need unit tests in top of that, but in my experience you can get away with far fewer. In general, I would say that Rust's type system, when combined with unit tests, is far more flexible, powerful, and easy to maintain than dynamic Python with only unit tests.
12_throw_away|10 months ago
1. Of course a type system is not as "flexible" as arbitrary test code.
2. Compiler-enforced type safety is many orders of magnitude easier to maintain than the equivalent unit tests
3. Defining rigorously enforced invariants with a type system is far, far more powerful than hoping you remembered to test all the important cases.
airstrike|10 months ago
bormaj|10 months ago
mabster|10 months ago
E.g. X is a list of strings Translate X to a list of indices Translate X back to a list of strings.
In that paragraph the input and output types are the same, but not complains about the second line.
I always have to introduce a variable with a new name.