• pewpew
    link
    fedilink
    31 day ago

    What part of Rust is fun?

    C is fun to me because the syntax is easy to understand and straight to the point. C is also great for learning low level coding, I find Rust so confusing

    • @HaraldvonBlauzahn@feddit.orgOP
      link
      fedilink
      4
      edit-2
      12 hours ago

      What part of Rust is fun?

      C is fun to me because the syntax is easy to understand and straight to the point.

      You probably had never the pleasure to search for bugs caused by C Undefined Behaviour in multithreaded code.

      When I was writing my diploma thesis, I was writing multi-threaded code for an embedded DSP system. Results were wrong all the time. I tracked it down to atan2() giving wrong results. I searched for about six weeks how to fix that and it disappeared when I changed the position of the program’s data segment.

      (If the concept of Undefined Behaviour is new to you, I can recommend the web pages of Jens Regehr).

      The above debugging experience was 25 years ago. We have better languages now. Rust has no Undefined Behaviour. That means you can track any bug (except compiler bugs) deterministically down to where the actual logic of the code, and the model of it which was in your head depart. This is great.

      Rust is fun because you can compile a complex program and it runs.

      But industry is still working with a fifty year old language written for systems where 32 kilobytes were a lot of memory. At work, I am still searching for bugs in multi-threaded C code with manual memory management (the previous developer didn’t think this needs locks), and I have to explain to the CTO that no, wo won’t have a release this fall, while the company literally drowns in technical debt.

      • pewpew
        link
        fedilink
        28 hours ago

        Ok fair point. I mainly code in C for making GBA games and random projects, so I haven’t done much multithreaded work

      • @zaphod@sopuli.xyz
        link
        fedilink
        110 hours ago

        I searched for about six weeks how to fix that and it disappeared when I changed the position of the program’s data segment.

        So it was a linker issue? I wouldn’t call that undefined behaviour in multithreaded code.

        But industry is still working with a fifty year old language written for systems where 32 kilobytes were a lot of memory.

        Especially for embedded and DSP stuff there are so many architectures that aren’t even supported by the Rust compiler. And on those systems 32 kiB of RAM is sometimes a lot of memory.

        • @HaraldvonBlauzahn@feddit.orgOP
          link
          fedilink
          16 hours ago

          So it was a linker issue?

          No, that would have resulted in a linker error, not random undefined behaviour

          But industry is still working with a fifty year old language written for systems where 32 kilobytes were a lot of memory.

          Especially for embedded and DSP stuff there are so many architectures that aren’t even supported by the Rust compiler. And on those systems 32 kiB of RAM is sometimes a lot of memory.

          These niches still exist but they get rapidly smaller every year. Because:

          • Cheap hardware gets more powerful
          • Demands rise… even some electric toothbrushes are networked now
          • Rust support for embedded devices is rapidly expanding

          Plus:

          • In some domains, security is becoming a real issue
    • @Auli@lemmy.ca
      link
      fedilink
      English
      317 hours ago

      Also really easy to introduce bugs. But from how everyone online talks about being good developers is all you need. I don’t know how those bugs get there in the first place.

      • @HaraldvonBlauzahn@feddit.orgOP
        link
        fedilink
        3
        edit-2
        5 hours ago

        I don’t know how those bugs get there in the first place.

        Easy to explain.

        Visualizing program code as cables, this is how a shiny new program would look:

        And this how, for example in a commercial environment, or if the programmers are not absolute masters, such a program will look after 15 years of bug fixing, feature requests, urgent changes, deadlines, and unfinished restructurings:

        The thing is that especially C code contains tons of implicit invariants which you simply cannot maintain in such code.

        And don’t forgot that the picture above shows perhaps 500 cables, but a codebase can easily contain 50000 lines of code…

    • @asdfasdfasdf@lemmy.world
      link
      fedilink
      521 hours ago

      Rust us way easier to understand for me (and I’d guess most people) than C.

      Rust is fun because it’s the only mainstream language with an affine type system, which allows some really cool patterns like the typestate pattern. And the fact that there’s no inheritance or null or exceptions is amazing.

      • @Nalivai@lemmy.world
        link
        fedilink
        51 day ago

        The first picture isn’t what people write, even though it’s technically compilable, it’s not what C is.
        The second is a normal syntax, pretty simple to understand if you write enough code.
        C is very simple language at it’s core, and it allows for it to be used in a very complicated systems.

      • @db2@lemmy.world
        link
        fedilink
        -71 day ago

        Were you trying to post examples of it being easy or do you actually find those hard?

        • esa
          link
          fedilink
          71 day ago

          I find the C type syntax turgid. It’s fine for the most basic types, but the name-in-the-middle style doesn’t scale at all, and it’s not hard to understand why later languages separate name and type, no matter which side of the name the type goes on.

          I find Rust easier to read in that regard, even though picking <> for generics was likely done to be familiar for C++/Java types rather than easy to parse. (See also: the bastion of the turbofish)

    • @slacktoid@lemmy.ml
      link
      fedilink
      English
      221 day ago

      Rust requires you to unlearn some of the C and CPP habits. And so it’s like learning a language that approaches things differently. That is pretty fun to see how another language solves a problem etc. I think rust is a very fun and interesting language tbh. But you are free to not like it, that’s all good man. That’s why we have different languages. After getting into rust, for me, you need to convince me to use C or Cpp, they have their niches for sure, but rust allows that too like embedded programming etc.

      • This checks out. I tried some Rust coding challenges and couldn’t get my stuff to compile mostly. When I see the solution it seems straightforward but also not intuitive.