• Ziglin (it/they)@lemmy.world
    link
    fedilink
    English
    arrow-up
    5
    ·
    4 days ago

    Why is literally nothing equivalent to None? Is it because None is the default value of an optional parameter? (If so why oh why is it optional)

    • spooky2092@lemmy.blahaj.zone
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      4 days ago

      Because nothing isn’t something, and something is true. It’s base Boolean logic where everything is either true or false. Null/nothing is false.

      It’s a weird way to think about conditionals, but it makes sense when you use them in real examples. In my case, I use them like this when I need to make sure that a variable has a value. So I can do something like

      If(variable){do things with the variable}else{do stuff when the variable doesn’t exist}

          • Ziglin (it/they)@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            3 days ago

            That makes a lot more sense, thanks I did see in the syntax highlighting that it was a keyword but forgot that none of them took parameters.

        • spooky2092@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          4 days ago

          No it’s not, “” (a null/empty string) is the parameter. Not every function needs a parameter to be valid, and negation is one of them. Negating nothing is something, so “not()” = “not(null)” = “not(false)” = “true”