Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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
Code Project
  1. Home
  2. The Lounge
  3. Rust and its ways

Rust and its ways

Scheduled Pinned Locked Moved The Lounge
csharpdotnetquestionlounge
6 Posts 4 Posters 0 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rob Philpott
    wrote on last edited by
    #1

    Good morning CodeProject! I’ve decided to teach myself something new - apparently it’s important for older people to do that to stop them going mental. So behind the back of my loving, dependable and reliable C# I’ve been having a risqué affair with Rust. Turns out that developing in Rust is about 30% expressing your intention in code and 70% arguing with a bad-tempered bureaucratic compiler for who simply nothing seems good enough. I decided my first project would be a Suduko solver, which is done and it works, but there was an interesting point in the development where different runs would dish out differing results. I was using a HashSet internally, and like in .NET you shouldn’t make any assumptions about the order of the items if you iterate over it. Fair enough, but I would expect it to be consistent in that ordering between say releases of the .NET framework. Not so in Rust. Here’s a Rust program:

    use std::collections::HashSet;

    fn main() {

    let mut set = HashSet::new();
    
    for n in 0..5 {
        set.insert(n);
    }
    
    for n in set {
        println!("{}", n);
    }
    

    }

    And here’s the output from running it twice: 0 3 2 1 4 and 0 2 1 3 4 Interesting huh? Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow. I spoke with 'Gemini' about it yesterday and it agreed it's interesting, so thought I'd share it. :)

    Regards, Rob Philpott.

    P A M 3 Replies Last reply
    0
    • R Rob Philpott

      Good morning CodeProject! I’ve decided to teach myself something new - apparently it’s important for older people to do that to stop them going mental. So behind the back of my loving, dependable and reliable C# I’ve been having a risqué affair with Rust. Turns out that developing in Rust is about 30% expressing your intention in code and 70% arguing with a bad-tempered bureaucratic compiler for who simply nothing seems good enough. I decided my first project would be a Suduko solver, which is done and it works, but there was an interesting point in the development where different runs would dish out differing results. I was using a HashSet internally, and like in .NET you shouldn’t make any assumptions about the order of the items if you iterate over it. Fair enough, but I would expect it to be consistent in that ordering between say releases of the .NET framework. Not so in Rust. Here’s a Rust program:

      use std::collections::HashSet;

      fn main() {

      let mut set = HashSet::new();
      
      for n in 0..5 {
          set.insert(n);
      }
      
      for n in set {
          println!("{}", n);
      }
      

      }

      And here’s the output from running it twice: 0 3 2 1 4 and 0 2 1 3 4 Interesting huh? Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow. I spoke with 'Gemini' about it yesterday and it agreed it's interesting, so thought I'd share it. :)

      Regards, Rob Philpott.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Interesting indeed. My guess is that the Rust folks will say that that behaviour is by design, to stop you relying on assumptions about implementation details. In other words to encourage (probably can't go as far as 'enforce') robust algorithms.

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      R 1 Reply Last reply
      0
      • P Peter_in_2780

        Interesting indeed. My guess is that the Rust folks will say that that behaviour is by design, to stop you relying on assumptions about implementation details. In other words to encourage (probably can't go as far as 'enforce') robust algorithms.

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        You know, I hadn't thought of that. By design, so that weirdness comes out early rather than later. Sounds like something the Rust brigade would do - good thinking!

        Regards, Rob Philpott.

        1 Reply Last reply
        0
        • R Rob Philpott

          Good morning CodeProject! I’ve decided to teach myself something new - apparently it’s important for older people to do that to stop them going mental. So behind the back of my loving, dependable and reliable C# I’ve been having a risqué affair with Rust. Turns out that developing in Rust is about 30% expressing your intention in code and 70% arguing with a bad-tempered bureaucratic compiler for who simply nothing seems good enough. I decided my first project would be a Suduko solver, which is done and it works, but there was an interesting point in the development where different runs would dish out differing results. I was using a HashSet internally, and like in .NET you shouldn’t make any assumptions about the order of the items if you iterate over it. Fair enough, but I would expect it to be consistent in that ordering between say releases of the .NET framework. Not so in Rust. Here’s a Rust program:

          use std::collections::HashSet;

          fn main() {

          let mut set = HashSet::new();
          
          for n in 0..5 {
              set.insert(n);
          }
          
          for n in set {
              println!("{}", n);
          }
          

          }

          And here’s the output from running it twice: 0 3 2 1 4 and 0 2 1 3 4 Interesting huh? Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow. I spoke with 'Gemini' about it yesterday and it agreed it's interesting, so thought I'd share it. :)

          Regards, Rob Philpott.

          A Offline
          A Offline
          Amarnath S
          wrote on last edited by
          #4

          Rob Philpott wrote:

          apparently it’s important for older people to do that to stop them going mental

          Using Rust to de-rust your mind.

          1 Reply Last reply
          0
          • R Rob Philpott

            Good morning CodeProject! I’ve decided to teach myself something new - apparently it’s important for older people to do that to stop them going mental. So behind the back of my loving, dependable and reliable C# I’ve been having a risqué affair with Rust. Turns out that developing in Rust is about 30% expressing your intention in code and 70% arguing with a bad-tempered bureaucratic compiler for who simply nothing seems good enough. I decided my first project would be a Suduko solver, which is done and it works, but there was an interesting point in the development where different runs would dish out differing results. I was using a HashSet internally, and like in .NET you shouldn’t make any assumptions about the order of the items if you iterate over it. Fair enough, but I would expect it to be consistent in that ordering between say releases of the .NET framework. Not so in Rust. Here’s a Rust program:

            use std::collections::HashSet;

            fn main() {

            let mut set = HashSet::new();
            
            for n in 0..5 {
                set.insert(n);
            }
            
            for n in set {
                println!("{}", n);
            }
            

            }

            And here’s the output from running it twice: 0 3 2 1 4 and 0 2 1 3 4 Interesting huh? Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow. I spoke with 'Gemini' about it yesterday and it agreed it's interesting, so thought I'd share it. :)

            Regards, Rob Philpott.

            M Offline
            M Offline
            markkuk
            wrote on last edited by
            #5

            Rob Philpott wrote:

            Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow.

            According to the docs[^], this is done to prevent HashDoS[^] attacks.

            R 1 Reply Last reply
            0
            • M markkuk

              Rob Philpott wrote:

              Something non-deterministic is going on. I haven’t debugged the HashSet yet to find out, but I’m presuming it’s using some random number or aspect of time somehow.

              According to the docs[^], this is done to prevent HashDoS[^] attacks.

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #6

              Aha! I should, perhaps, read the documentation sometimes, what with it being the first sentence and that. The crazy lengths we are forced to go to stop mitigate people attacking our software...

              Regards, Rob Philpott.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

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