Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Learning to program in rust

Learning to program in rust

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
53 Posts 31 Posters 3 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M This user is from outside of this forum
    M This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #3

    The amount of people on the internet seriously complaining that both Rust error handling sucks and that .unwrap(); is too verbose is just staggering.

    M W D 3 Replies Last reply
    14
    • K [email protected]
      This post did not contain any content.
      M This user is from outside of this forum
      M This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #4

      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.

      M A 2 Replies Last reply
      21
      • M [email protected]

        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.

        M This user is from outside of this forum
        M This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #5

        I’m a OOP programmer.

        I wrap everything within Arc<Mutex<>>.

        I’m a happy dev.

        M 1 Reply Last reply
        9
        • K [email protected]
          This post did not contain any content.
          K This user is from outside of this forum
          K This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #6

          This is my experience every time I return to learning rust. I’m guessing that if I used it more often than once a quarter with hobby projects I’d stop falling into the same traps.

          B E 2 Replies Last reply
          6
          • M [email protected]

            The amount of people on the internet seriously complaining that both Rust error handling sucks and that .unwrap(); is too verbose is just staggering.

            M This user is from outside of this forum
            M This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #7

            I think the problem is that many introductory examples use unwrap, so many beginner programmers don’t get exposed to alternatives like unwrap_or and the likes.

            E 1 Reply Last reply
            2
            • M [email protected]

              I’m a OOP programmer.

              I wrap everything within Arc<Mutex<>>.

              I’m a happy dev.

              M This user is from outside of this forum
              M This user is from outside of this forum
              [email protected]
              wrote on last edited by [email protected]
              #8

              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.

              P 1 Reply Last reply
              1
              • M [email protected]

                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.

                P This user is from outside of this forum
                P This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #9

                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.

                M tatterdemalion@programming.devT 2 Replies Last reply
                0
                • M [email protected]

                  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.

                  A This user is from outside of this forum
                  A This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #10

                  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?

                  M F Q E 4 Replies Last reply
                  2
                  • A [email protected]

                    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?

                    M This user is from outside of this forum
                    M This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #11

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

                    1 Reply Last reply
                    1
                    • P [email protected]

                      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.

                      M This user is from outside of this forum
                      M This user is from outside of this forum
                      [email protected]
                      wrote on last edited by [email protected]
                      #12

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

                      1 Reply Last reply
                      0
                      • I This user is from outside of this forum
                        I This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #13

                        Me, every time I try searching a Rust question.

                        That's easy. Just do:

                        fn is_second_num_positive() -> bool {
                            let input = "123,-45";
                            let is_positive =
                                input.split(',')
                                .collect::<Vec<&str>>()
                                .last()
                                .unwrap()
                                .parse::<i32>()
                                .unwrap()
                                .is_positive();
                            is_positive
                        }
                        
                        S 1 Reply Last reply
                        4
                        • A [email protected]

                          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?

                          F This user is from outside of this forum
                          F This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #14

                          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

                          1 Reply Last reply
                          1
                          • K [email protected]
                            This post did not contain any content.
                            M This user is from outside of this forum
                            M This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #15

                            Learning C, that smasher would never have stopped.

                            B 1 Reply Last reply
                            20
                            • I [email protected]

                              Me, every time I try searching a Rust question.

                              That's easy. Just do:

                              fn is_second_num_positive() -> bool {
                                  let input = "123,-45";
                                  let is_positive =
                                      input.split(',')
                                      .collect::<Vec<&str>>()
                                      .last()
                                      .unwrap()
                                      .parse::<i32>()
                                      .unwrap()
                                      .is_positive();
                                  is_positive
                              }
                              
                              S This user is from outside of this forum
                              S This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #16

                              Can't resist pointing out how you should actually write the function in a "real" scenario (but still not handling errors properly), in case anyone wants to know.

                              If the list is guaranteed to have exactly two elements:

                              fn is_second_num_positive_exact(input: &str) -> bool {
                                  let (_, n) = input.split_once(',').unwrap();
                                  n.parse::<i32>().unwrap() > 0
                              }
                              

                              If you want to test the last element:

                              fn is_last_num_positive(input: &str) -> bool {
                                  let n = input.split(',').next_back().unwrap();
                                  n.parse::<i32>().unwrap() > 0
                              }
                              

                              If you want to test the 2nd (1-indexed) element:

                              fn is_second_num_positive(input: &str) -> bool {
                                  let n = input.split(',').nth(1).unwrap();
                                  n.parse::<i32>().unwrap() > 0
                              }
                              
                              E B 2 Replies Last reply
                              10
                              • A [email protected]

                                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?

                                Q This user is from outside of this forum
                                Q This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #17

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

                                1 Reply Last reply
                                3
                                • M [email protected]

                                  Learning C, that smasher would never have stopped.

                                  B This user is from outside of this forum
                                  B This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #18

                                  It would also be emitting significantly less helpful messages.

                                  M 1 Reply Last reply
                                  16
                                  • B [email protected]

                                    It would also be emitting significantly less helpful messages.

                                    M This user is from outside of this forum
                                    M This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by [email protected]
                                    #19

                                    "What messages?"

                                    Lol yes

                                    C 1 Reply Last reply
                                    12
                                    • S [email protected]

                                      Can't resist pointing out how you should actually write the function in a "real" scenario (but still not handling errors properly), in case anyone wants to know.

                                      If the list is guaranteed to have exactly two elements:

                                      fn is_second_num_positive_exact(input: &str) -> bool {
                                          let (_, n) = input.split_once(',').unwrap();
                                          n.parse::<i32>().unwrap() > 0
                                      }
                                      

                                      If you want to test the last element:

                                      fn is_last_num_positive(input: &str) -> bool {
                                          let n = input.split(',').next_back().unwrap();
                                          n.parse::<i32>().unwrap() > 0
                                      }
                                      

                                      If you want to test the 2nd (1-indexed) element:

                                      fn is_second_num_positive(input: &str) -> bool {
                                          let n = input.split(',').nth(1).unwrap();
                                          n.parse::<i32>().unwrap() > 0
                                      }
                                      
                                      E This user is from outside of this forum
                                      E This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #20

                                      Can still use .is_positive(), though...

                                      1 Reply Last reply
                                      1
                                      • M [email protected]

                                        I think the problem is that many introductory examples use unwrap, so many beginner programmers don’t get exposed to alternatives like unwrap_or and the likes.

                                        E This user is from outside of this forum
                                        E This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #21

                                        Yeah, we onboarded some folks into a Rust project last year and a few months in, they were genuinely surprised when I told them that unwrapping is pretty bad. Granted, they probably did read about it at some point and just forgot, but that isn't helped by lots of code using .unwrap() either.

                                        1 Reply Last reply
                                        2
                                        • A [email protected]

                                          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?

                                          E This user is from outside of this forum
                                          E This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #22

                                          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.

                                          B D 2 Replies Last reply
                                          4
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups