Remix.run Logo
d0mine 4 days ago

Do you believe that Rust's type system is as flexible, powerful, and easy to maintain as unit tests in Python?

MrJohz 4 days ago | parent | next [-]

One of the big advantages of Rust's type system is that, if you decide you want to change something (add a parameter, give a type a lifetime, rewrite an entire module), you can just do that, and then follow the errors until they're all gone. Often, once the types have been fixed again, the result will work first time when you try and run it.

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 4 days ago | parent | prev | next [-]

I write and test a lot of both rust and python, so I can say quite confidently:

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.

d0mine 3 days ago | parent [-]

Your 2-3 points remind me of the quote by Ludwig Wittgenstein: “The limits of my language means the limits of my world.”

Of course if you limit yourself only to problems that can be effectively solved by type system, then it may work. It is like limiting yourself only to those text processing tasks where regexs work. Yes, some text processing tasks may be much more effectively solved using a regex. But it is obvious that at some point in a more general case grep can’t replace python. It may be less apparent for compiler vs. python case but the general logic is the same.

12_throw_away 3 days ago | parent | next [-]

So you asked a question, didn't like the answer, and decided to just start insulting people instead?

d0mine 2 days ago | parent [-]

No disrespect intended. I’m making purely technical point.

pdimitar 3 days ago | parent | prev [-]

Nobody is "limiting" themselves to anything. That's not a counterargument you're making.

We all deploy to production, dude.

Strong static typing (Rust), even only dynamic strong typing + pattern matching (Elixir), are leagues better than Python. Literal 3x - 7x less code and less production errors both in Elixir and Rust, over the course of 5 years.

You're the one limiting yourself. Expand your horizons.

airstrike 4 days ago | parent | prev [-]

No, it's more flexible, more powerful, and easier to maintain than unit tests in Python.