• mholiv@lemmy.world
    link
    fedilink
    arrow-up
    23
    arrow-down
    2
    ·
    15 hours ago

    Skill Issue.

    For reals though adopting a functional style of programming makes rust extremely pleasant . It’s only when people program in object oriented styles that this gets annoying.

    No loops, and no state change make rust devs happy devs.

      • mholiv@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        edit-2
        12 hours ago

        I mean yah. That’s what it takes. But like when I try to write code around Arc<_> the performance just tanks in highly concurrent work. Maybe it’s an OOP rust skill issue on my end. Lol.

        Avoiding this leads, for me at least, to happiness and fearless, performant, concurrent work.

        I’m not a huge fan of go-lang but I think they got it right with the don’t communicate by sharing memory thing.

        • PlexSheep@infosec.pub
          link
          fedilink
          arrow-up
          1
          ·
          12 hours ago

          You mean mutex? Arc allows synchronous read only access by multiple threads, so it’s not a performance bottleneck. Locking a mutex would be one.

          • mholiv@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            12 hours ago

            I mean it could be Mutex, or Rwlock or anything atomic. It’s just when I have to out stuff into an Arc<> to pass around I know trouble is coming.

    • AnarchoEngineer@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      3
      ·
      12 hours ago

      I just started learning rust like two days ago and I haven’t had too many issues with OOP so far… is it going to get considerably worse as the complexity of my projects increases?

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        5
        ·
        4 hours ago

        The thing with OOP, particularly how it’s used in GCed languages, is that it’s all about handing references out to wherever and then dealing with the complexity of not knowing who has access to your fields via getters & setters, or by cloning memory whenever it’s modified in asynchronous code.

        Rust has quite the opposite mindset. It’s all about tracking where references go. It pushes your code to be very tree-shaped, i.e. references typically¹ only exist between a function and the functions it calls underneath. This is what allows asynchronous code to be safe in Rust, and I would also argue that the tree shape makes code easier to understand, too.

        But yeah, some of the patterns you might know from OOP will not work in Rust for that reason. You will likely need to get into a different mindset over time.

        Also just in case: We are talking OOP in the sense of the paradigm, i.e. object-oriented.
        Just using objects, i.e. data with associated functions/methods, that works completely normal in Rust.

        ¹) If you genuinely need references that reach outside the tree shape, which is mostly going to be the case, if you work with multiple threads, then you can do so by wrapping your data structures in Arc<Mutex<_>> or similar. But yeah, when learning, you should try to solve your problems without these. Most programs don’t need them.

      • qaz@lemmy.world
        link
        fedilink
        English
        arrow-up
        4
        ·
        9 hours ago

        It will become more complex when you start needing circular references in your datastructures.

      • felsiq@lemmy.zip
        link
        fedilink
        arrow-up
        2
        ·
        10 hours ago

        Worse in the sense of more errors, sure, but as you go you’ll pick up more of the rust patterns of thinking and imo it’s very worth it. It’s an odd blend and can be a bit verbose but I definitely prefer it to a pure OO or pure functional style language personally

      • mholiv@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        12 hours ago

        You’ll be fine. You will learn the lifetime stuff and all will work out. It’s not that bad to be honest.