• aluminium@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    18 days ago

    Sounds better than coming up with the most mindfucking ways to please the borrowchecker in a large rust codebase

    (Skill issue probably, i know)

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

      Rule of thumb, which I feel gets you 80% there:

      If you store data in a struct, you want that struct to have ownership of that data. So, avoid storing references in structs.
      If you need to pass data into a function, you usually want to pass it as a reference.

      This makes it so you have your data stored in some place with the ownership and from there you just pass data down into functions as references. It forces you to structure your program like a tree (which is often a very good idea to begin with).

      • AggressivelyPassive@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        18 days ago

        Rust needs some layer on top to make it more usable for the typical business apps.

        I tried to build simple CRUD apps, but it’s still a huge pain, because there’s just so much stuff I need to do myself and so much low level overhead that I need to keep in mind.

        Java is worse in many ways, but for cobbling together a mess that barely manages to do its thing, it’s really great.

        • UnRelatedBurner@sh.itjust.works
          link
          fedilink
          arrow-up
          5
          ·
          18 days ago

          Isn’t that the point? It doesn’t let you write bad code, thus when you did manage to get something compiled it’s close to C speed. Also I kinda like that it tells me ebery lil mistake, it reminds me when I forgot to delete/change something

          • AggressivelyPassive@feddit.de
            link
            fedilink
            arrow-up
            1
            ·
            18 days ago

            Compared to Java, it makes me write the same data structures three or four times.

            Just an example: if I want to be able to insert a struct via Diesel, I need to write the actual entity, an entity without the id for inserts and maybe some other structures for queries. Also, I need to write a schema file defining the DB plus an SQL statement for actually creating the needed tables.

            Another example: explorative testing. Sometimes you need to disable chunks of code for testing purposes. Maybe that long running computation or a DB query, etc. Rust often forces you to write a bunch of “corrections” to make the code seem correct again.

            I get that this is useful, but for my line of work, it’s just a pain in the ass.

            • UnRelatedBurner@sh.itjust.works
              link
              fedilink
              arrow-up
              2
              ·
              17 days ago

              I can’t relate to these, but Rust is lacking in some aspects that’s no secret. That’s why it barely has GUIs or object oriented coding. It’s usable for both, but why would you. You don’t have to use rust for what it’s not ment to be used at.

              it’s trying it’s best tho, lol. I wonder if in X years, it’ll be like c++, a Frank Einstein of syntax to be usable for everything.