• Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    9
    ·
    21 hours ago

    you can have a better data structure in any language, but rarely someone will bother doing that for booleans

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      42 minutes ago

      Yeah I do wonder if we need an easier way to declare these things because programmers are lazy and even in Rust I wouldn’t always bother.

      You can kind of do it in Typescript with strings:

      function create_user(role: "admin" | "normal")
      

      But of course the downside is they are strings at runtime. I’m sure it’s possible though.

    • Traister101@lemmy.today
      link
      fedilink
      arrow-up
      3
      ·
      18 hours ago

      Right cause the boolean isn’t a named type. If you have two possible states that can be represented with a boolean, or an enum of the two possible states which embeds more info into the callsite