News for hackers. Stuff that matters.
Re:Rust needs a web framework for lazy developers by kaoD on Monday October 07, 2024 @02:45AM (#41763386)
As someone who loves both TS and Rust: you couldn't be more wrong. TS is not even half as good at making invalid states unrepresentable.

A simple example of the (many) things you can't do in TS:

    struct StateStart;

    struct StateEnd;

    impl StateStart {
      fn foo(self) -> StateEnd {
        StateEnd
      }
    }

    fn main() {
      let start = StateStart;
      let end = start.foo();
      let another_end = start.foo(); // this won't compile
    }
Try doing that without a runtime crash in TS. Super useful pattern for state machines (which are the building block of computing).

I miss more features of Rust in TS that features of TS in Rust. All the time.

Re:Rust needs a web framework for lazy developers by WuxiFingerHold on Monday October 07, 2024 @07:16AM (#41764868)
Interesting, great example. This kind of compile time safety can't be achieved without borrow checker, I guess? I'm now thinking hard if there's some type magic similar to the exhaustive checks for Typescript discriminated unions ("kind satisfies never" checks in switch statements).
Re:Rust needs a web framework for lazy developers by kaoD on Monday October 07, 2024 @07:29AM (#41764942)
I've been trying to come up with a similar pattern in TS many times but I think you cannot do this because all types in JS (and thus in TS) are (1) aliasable by just binding them and (2) only passed by reference (including `this`).

But TS has so many dark magical patterns that I'm still hoping to be proven wrong.