• jtrek@startrek.website
    link
    fedilink
    arrow-up
    36
    ·
    10 hours ago

    I use keyword arguments in Python to minimize this pain. Instead of

    
    create_user("Bob", True, False)
    

    it’s

    
    create_user(name="Bob", admin=True, send_email=False)
    

    JavaScript makes that more cumbersome with the object thing , but it’s better than nothing.

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

      This! There’s also a longstanding open issue on rust to allow a similar way to pass keyword/named arguments. IMO every modern language should have something like this. Makes all the difference when reading code.

      Inlay hints from your editor are a good help, but this should be built into the language.

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

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

          • Traister101@lemmy.today
            link
            fedilink
            arrow-up
            1
            ·
            2 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

    • Riskable@programming.dev
      link
      fedilink
      English
      arrow-up
      3
      ·
      8 hours ago

      Thank you for posting this comment. I came here to write the exact same thing and now I don’t have to!

      👍

    • ugo@feddit.it
      link
      fedilink
      arrow-up
      2
      ·
      8 hours ago

      zig uses anonymous structs for the same effect

      doWork(.{
          .flurbify = true,
          .flurbification_intensity = 1001,
      });