• Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    17 hours ago

    default values is one of my pet-peeves after using Python regularly. I wish more languages would let you just do something like def do_thing(arg=default_value) without hoops like builder pattern, function overloading, or whatnot

    • SlurpingPus@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      9 hours ago

      I mean, the go-to approach in Lisp, for example, is to have null as the default value (which doubles for false in there). And check for that in the function.

        • SlurpingPus@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          8 hours ago

          In Lisp, at least the Emacs Lisp with which I have experience, it’s customary to put in nil (Lisp’s null) for any omitted arguments in the middle that you can’t be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I’m guessing coders need to check for both undefined and null in these circumstances.

          Overall, it’s remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere.