• orangeboats@lemmy.world
    link
    fedilink
    arrow-up
    25
    arrow-down
    2
    ·
    5 days ago

    This is why I try my damnedest not to write in weakly typed languages.

    string + object makes no logical sense, but the language will be like “'no biggie, you probably meant string + string so let’s convert the object to string”! And so all hell breaks loose when the language’s assumption is wrong.

    • Blackmist@feddit.uk
      link
      fedilink
      English
      arrow-up
      3
      ·
      4 days ago

      Some automatic conversion is fine.

      a=3+0.2

      print(“Hello {name}. You are {age} years old”)

      That kind of thing. But the principle of least surprise definitely applies. If you get to the point where you’re adding two booleans and a string, I feel like the language should at least say something. At least until the technology exists for it to physically reach out of your screen and slap you.

    • zalgotext@sh.itjust.works
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      5 days ago

      You don’t necessarily need types for that kind of thing though, a strict linter that flags that code works just as well