• 0 Posts
  • 11 Comments
Joined 2 years ago
cake
Cake day: March 5th, 2024

help-circle
  • It’s because they wanted to hack control flow functionality into expressions. Returning None is actually returning something, but never is just a placeholder for any type when they want to do things that may exit the expression entirely. This is an example in the docs

    let num: u32 = match get_a_number() {
        Some(num) => num,
        None => break,
    };
    

    Break exits the expression without ever producing a value.

    This is an unfortunate wart to appease a desire to those that want to be able to write code like they do in legacy languages. There should have been better ways to do this without being a hack IMO



  • This is a pretty straightforward utility function that wouldn’t be that hard to test. It’s normal to have standards for code coverage as part of the review process, I don’t code in C but I’d be surprised if setting any of that up is actually that burdensome.

    I disagree with your reference of that quote being applicable here though. In fact, adding unit tests is the exact opposite: that quote is saying ‘if your answer is “make less mistakes” …’ Unit tests in general are an acceptance of the fact that we will fail to be perfect and we need to mitigate that with extra checks. The article already said it had two human reviewers, so they’re not opposed to extra process to help ensure quality, unit tests are just another (actually very cheap) extra step.