An unofficial, read-only Hacker News reader.

2035 came early (opens external site)

1039 points by setheron 6 days ago | fzakaria.com | 382 comments on HN

View full thread · View on Hacker News

Comment thread (10)

  1. In the last few decades the hype around GC kind of faded because GC is literally a complex solution designed to fix only one single class of leaks - memory leaks - which often makes other kinds of leaks (mutex, file descriptors, handles, ..) actually harder to handle unless the language is carefully designed around them. Just look at Java's `try()` or `with` in Python, etc, which are afterthoughts added later. RAII may be rudimental but it can potentially fix all classes of leaks by introducing deterministic lifetimes and scopes which aren't tied with the resource itself. There are other solutions for this? yes of course, but the success of Rust which is literally built over a stronger, deterministic form of RAII kind of makes debatable whether a better system is needed at all. Especially since LLMs are excellent at Rust and kind of make opting for "weird" languages moot. And I say this as a person which _loves_ niche languages and language design.

    Nowadays you can probably vibe/slopcode whatever you need with just a bit of Rust, Python/shell scripts as glue and maybe Javascript if it's a webapp (but we'll likely replace that with WASM soon I'm afraid)

    Replies (1)
    1. Rust, unfortunately, lets you express lower bounds on lifetimes but not upper bounds. There is no way in Rust to express “this object must be released by that point in the program,” a guarantee which is extremely useful.
      Replies (1)
      1. It kinda does that, by using borrows. If A borrows B, then the upper bound of A's lifetime is the borrow of B. You can control the lifetime of the borrow by creating a new mutable reference to B at a particular point (works regardless of whether the original borrow was mutable or immutable).
        Replies (1)
        1. In this case you’re really setting a lower bound on the borrow of B, not an upper bound on the lifetime of A.

          I assure you this is not pedantry or a nitpick. The classic case here is if you want to borrow a local variable inside a thread… you need to ensure that the thread lifetime is bounded from above by the lifetime of the borrowed variable. This is why we have weird workarounds like std::thread::scope. If we could just express an upper bound on lifetime, it wouldn’t be necessary.

          Replies (1)
          1. I fail to see the difference between the lifetime of the variable being longer than the thread and the lifetime of the thread being shorter than the variable. I also fail to see how flipping it around would help eliminate std::thread::scope, which exists because of Rc cycles. Could you please show an example of what kind of code would be disallowed if upper bounds existed that is not possible today?
            Replies (1)
            1. Here is your example:

                use std::thread;
                fn main() {
                  let v = vec![1, 2, 3];
                  let handle = thread::spawn(|| {
                    println!("{:?}", v); // borrows `v`
                  });
                  handle.join().unwrap();
                }
              
              If lifetimes could have upper bounds then this would work.

              Continue this thread (1 replies) →