• kazaika@lemmy.world
    link
    fedilink
    arrow-up
    15
    ·
    6 days ago

    I’d argue that the reason this is so bad in other languages is because of horrible default implementations. Look at tostring in java, getting a somewhat printable object would be easy if the default implementation would use reflection or sth to print the object, but instead it prints hash gibberish no one cares about.

    • Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      7
      ·
      5 days ago

      I always hated the implementation for .toString() of Duration. It gives you a string like that: PT8H6M12.345S (not a hash)

      Apparently, it’s an ISO 8601 thing, but what the hell am I supposed to do with that?
      It’s not useful for outputting to end users (which is fair enough), but I don’t even want to write that into a log message.
      I got so used to this just being garbage that I would automatically call .toMillis() and write “ms” after it.

      Well, and not to gush about Rust too much, but I recently learned that its debug string representation is actually really good. As in, it’s better than my Java workaround, because it’ll even do things like printing 1000ms as 1s.
      And that’s just like, oh right, libraries can actually provide a better implementation than what I’ll slap down offhandedly.