• r00ty@kbin.life
    link
    fedilink
    arrow-up
    3
    ·
    1 month ago

    The problem with rust, I always find is that when you’re from the previous coding generation like myself. Where I grew up on 8 bit machines with basic and assembly language that you could actually use moving into OO languages… I find that with rust, I’m always trying to shove a round block in a square hole.

    When I look at other projects done originally in rust, I think they’re using a different design paradigm.

    Not to say, what I make doesn’t work and isn’t still fast and mostly efficient (mostly…). But one example is, because I’m used to working with references and shoving them in different storage. Everything ends up surrounded by Rc<xxx> or Rc<RefCell<xxx>> and accessed with blah.as_ptr().borrow().x etc.

    Nothing wrong with that, but the code (to me at least) feels messy in comparison to say C# which is where I do most of my day job work these days. But since I see often that things are done very different in rust projects I see online, I feel like to really get on with the language I need a design paradigm shift somewhere.

    I do still persist with rust because I think it’s way more portable than other languages. By that I mean it will make executable files for linux and windows with the same code that really only needs the standard libraries installed on the machine. So when I think of writing a project I want to work on multi platforms, I’m generally looking at rust first these days.

    I just realised this is programmerhumor. Sorry, not a very funny comment. Unless you’re a rust developer and laughing at my plight of trying to make rust work for me.

    • lengau@midwest.social
      link
      fedilink
      arrow-up
      1
      ·
      1 month ago

      In Python it’s really hard!

      def __eq__(self, other):
          ...
      

      How do you even write those subscripted hyphens???

  • kazaika@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 month 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
      0
      ·
      1 month 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.

      • bleistift2@sopuli.xyz
        link
        fedilink
        English
        arrow-up
        0
        ·
        26 days ago

        I don’t even want to write that into a log message.

        Why not? It’s a perfectly human readable representation of that duration, just as intended by ISO.

        what the hell am I supposed to do with that?

        Just as an example, we use that format to communicate durations between the frontend and backend.

        • Ephera@lemmy.ml
          link
          fedilink
          English
          arrow-up
          2
          ·
          26 days ago

          Well, because I’m of a very different opinion about its readability. If you know the format, then sure, you can mostly read it as expected. But our logs are often something that customers or sysadmins will want to read. If it says Retrying in PT5S... in there, they’ll think that’s a bug, rather than a duration.

          And yeah, I almost figured it was for de-/serialization. I guess, that’s something where I disagree with the designers of Java.
          In my opinion, you don’t ever want to rely on the implicit behavior of the language for your serialization needs, but rather want to explicitly write down how you’re serializing. You want to make a conscious decision and document that it’s the ISO 8601 format, so that if you need to hook up another language, you have a chance to use the same format. Or, if you need to change the format, so that you can change the one serialization function, rather than having to find all the places where a .toString() happens.

          Admittedly, the Java devs were between a rock and a hard place, due to them having to implement .toString() and the meaning of .toString() being kind of undefined, i.e. it’s never stated whether this is a format for serialization, for debugging or for displaying to the user. And then I guess, because it didn’t explicitly say “for debugging” on there, they felt it was important to go with a standard format.