←back to thread

517 points bkolobara | 1 comments | | HN request time: 0.204s | source
Show context
raphinou ◴[] No.45041946[source]
Though it's not the only benefit, I enjoy rust and fsharp's typesystems most when refactoring code. Fearless refactoring is the right expression here.
replies(1): >>45043262 #
estebank ◴[] No.45043262[source]
The only issue with it is that Rust's aversion to half-baked code means that you can't have "partially working code" during the refactor: you either finish it or bail on it, without the possibility to have inconsistent codebase state. This is particularly annoying for exploratory code.

On the other hand, that strictness is precisely what leads people to end up with generally reasonable code.

replies(3): >>45043412 #>>45043931 #>>45050355 #
tialaramex ◴[] No.45043412[source]
I find a healthy dose of todo!() is excellent for this.

    match foo {
      (3...=5, x, BLABLABLA) => easy(x),
      _ => todo!("I should actually implement this for non-trivial cases"),
    }
The nice thing about todo!() is that it type checks, obviously it always diverges so the type match is trivial, but it means this compiles and, so long as we don't cause the non-trivial case to happen, it even works at runtime.
replies(1): >>45043770 #
estebank ◴[] No.45043770[source]
The thing is I want an equivalent to `todo!()` for the type-system. A mode of operation where if you have some compile errors, you can still run tests. Like for example, if you have

    fn foo() -> impl Display {
        NotDisplay::new()
    }
and a test references `foo`, then it gets replaced for the purposes of the test with

    fn foo() -> impl Display {
        panic!("`NotDisplay` doesn't `impl Display`")
    }
This should not be part of the language, but part of the toolchain.

Same thing for the borrow-checker.

replies(4): >>45043997 #>>45044552 #>>45044842 #>>45050636 #
1. oasisaimlessly ◴[] No.45044842[source]
Sounds like 'Typed Holes'[1] in the Haskell ecosystem.

[1]: https://downloads.haskell.org/~ghc/7.10.3-rc1/users_guide/ty...