• 1 Post
  • 213 Comments
Joined 1 year ago
cake
Cake day: September 24th, 2023

help-circle






  • I think I disagree with everything here.

    Exceptions Are Much Easier to Work With

    Well, they’re “easier” in the same way that dynamic typing is easier. It’s obviously less work initially just to say “screw it; any error gets caught in main()”. But that’s short term easiness. In the long term its much more painful because:

    1. You don’t know which functions might produce errors, and therefore you don’t know where you should be even trying to handle errors. (Checked exceptions are the answer here but they are relatively rarely used in practice.)
    2. Actually handling errors properly often involves responding to errors from individual function calls - at least adding human readable context to them. That is stupidly tedious with exceptions. Every line turns into 5. Sometime it makes the code extremely awkward:
    try {
       int& foo = bar();
    } catch (...) {
       std::cout << "bar failed, try ...\n";
       return nullopt;
    }
    foo = 5;
    

    (It actually gets worse than that but I can’t think of a good example.)

    Over 100× less code! [fewer exception catching in their C++ database than error handling in a Go database]

    Well… I’m guessing your codebase is a lot smaller than the other one for a start, and you’re comparing with Go which is kind of worst case… But anyway this kind of proves my point! You only actually have proper error handling in 140 places - apparently mostly in tests. In other words you just throw all exceptions to main().

    System errors [he’s mainly talking about OOM, stack overflow & arithmetic errors like integer overflow]

    Kind of a fair point I guess. I dunno how you can reasonably stack overflows without exceptions. But guess what - Rust does have panic!() for that, and you can catch panics. I’d say that’s one of the few reasonable cases to use catch_unwind.

    Exceptions Lead to Better Error Messages

    Hahahahahaha. I dunno if a bare stack trace with NullPointerException counts as a “better error message”. Ridiculous.

    Exceptions Are More Performant

    Sure maybe in error handling microbenchmarks, or particularly extreme examples. In real world code it clearly makes little difference. Certainly not enough to choose an inferior error handling system.

    I would say one real reason to prefer exceptions over Result<>s is they are a fair bit easier to debug because you can just break on throw. That’s tricky with Result<> because creating a Err is not necessarily an error. At least I have not found a way to “break on Err”. You can break on unwrap() but that is usually after the stack has been unwound quite a bit and you lose all context.



    1. If your alternative is C++ then it removes the enormous burden of manually tracking lifetimes and doing manual memory management. C++ does have RAII which helps with that enormously but even then there are a gazillion footguns that Rust just doesn’t have - especially with the newer stuff like rvalue references, std::move, coroutines etc. It also saves you from C++'s dreaded undefined behaviour which is everywhere.

    2. It has a very strong (and nicely designed) type system which gives an “if it compiles it works” kind of feel, similar to FP languages like Haskell (so they say anyway; I’ve not used it enough to know). The borrow checker strongly pushes you to write code in a style that somehow leads to less buggy code. More compiler errors, but much less debugging and fixing bugs.

    3. The libraries and APIs are generally very well designed and nice to use. If you’ve ever used Dart or Go think how nice the standard library is compared to JavaScript or PHP. It took C++ like 2 decades to get string::starts_with but Rust started with it (and much more!).

    4. Fast by default.

    5. Modern tooling. No project setup hassle.

    6. It’s a value based language, not reference based. References are explicit unlike JavaScript, Java, C#, etc. This is much nicer and makes things like e.g. copying values a lot easier. JavaScript’s answer for ages was “serialise to JSON and back” which is crazy.

    Downsides:

    1. Slow compilation sometimes. I’d say it’s on par with C++ these days.

    2. Async Rust is kind of a mess. They shipped an MVP and it’s still kind of hard to use and has unexpected footguns, which is a shame because sync Rust avoids footguns so well. Avoid async Rust if you can. Unfortunately sometimes you can’t.

    3. Interop with C++ is somewhat painful because Rust doesn’t have move constructors.

    Great language overall. Probably the best at the moment.


  • I don’t think so. At this point Linux isn’t really held back by software availability - 90% of things are web based now and games apparently work pretty well (certainly better than on Mac).

    The main issue is hardware support and driver quality. Especially on laptops, if you install Linux you’re really rolling the dice on whether or not you’ll get something that works.

    Someone always replies to comments like these with “it works for me!” which is not really relevant when it has to work for everyone.

    For a while at work I was in the Linux slack channel even when I was using a Mac, just to follow the amusing problems people had (and they had a lot!).

    Then I moved jobs and have a Linux laptop… I get to experience it first hand. Hard reboot when it runs out of RAM, or 20% or the time when you undock it. Doesn’t work at 60Hz/4K on some work monitors but only if you are using HDMI. The exact same laptop model & OS works for other people. Battery life is hilarious. I don’t think I’ve ever got over 2 hours.










  • One nice thing about XML is that there’s an official way to link to the schema from within the document. If you do that you can easily automatically validate it, and even better you get fantastic IDE support via Red Hat’s LSP server. Live validation, hover for keys, etc.

    It’s a really nice experience and JSON schema can’t really match it.

    That said, XML just has the wrong data model for 99% of use cases.