• Jesus_666@lemmy.world
    link
    fedilink
    English
    arrow-up
    11
    ·
    edit-2
    4 days ago

    C#. Until semi-recently it was only used for value types (as reference types are supposed to be nullable by default) but these days you can enable explicit nullables, which means that you have to explicitly specify nullability even for reference types.

    I like explicit nullables. It’s not much more work to type those question marks and it adds a safeguard against null showing up where it shouldn’t.

    I specifically inspired insisted on it for this picture because the code on the sign uses capitalized names for something that isn’t a class, which is a very C# thing to do.

    • itslilith@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      4
      ·
      6 days ago

      That sounds similar in purpose to Haskell’s ‘Maybe’ or Rust’s ‘Option’ enum, right?

      I still think that the null type was a mistake that introduces unnecessary bugs. But I’m glad to see more languages are taking measures against it

      • tuna@discuss.tchncs.de
        link
        fedilink
        arrow-up
        2
        ·
        6 days ago

        Someone can correct me if im wrong but I think nullable in C# still doesnt force you to do a null check before accessing properties or methods, however I believe it does give a type error when using a nullable type where non-nullable is expected, which is good. So it might not be 1-to-1 but it fulfills a similar purpose for sure.

        Coming from a rust background I would have sure appreciated my workplace enabling the nullable feature on our main codebase from the start. I’ve run out of patience for null errors :(