• pivot_root@lemmy.world
      link
      fedilink
      arrow-up
      47
      arrow-down
      1
      ·
      edit-2
      1 day ago

      Look, I’m not saying the wheel is wrong. It rotates, but what if two people try to turn the wheel at the same time, in opposite directions?

      What if—instead of risking misuse of the wheel—we have a my_wheel::Wheel, which only one person can rotate at any given time? The multiverse could enforce this safety at compile time by making it impossible for there to exist a universe where two people both think they own the right to rotate the wheel. In fact, it could even make it impossible for me to lend out the wheel to more than one person at a time.

      And, maybe… we could make the wheel even better. Cars rest on top of wheels, sure. But what if I wanted to make a car that rests on top of other cars? If we rotate the super-car’s wheels, we don’t want to make the sub-cars flap around—we want the sub-car wheels to rotate. It would be more future-proof to make a Wheel trait, then to make RubberTyre implement Wheel. Then, if we ever needed to make cars into wheels, we could have them also implement Wheel—but delegate the responsibility of rotating to their own wheels.

      In fact, we should make it into a whole library. Our other projects could need wheels. Mr. Mittens might need them eventually!

    • BatmanAoD@programming.dev
      link
      fedilink
      arrow-up
      128
      arrow-down
      2
      ·
      edit-2
      1 day ago

      Hello, Rust developer. [My name, etc.] It works fine, and is written in C++. [Rest of challenge is the same.]

      Truly diabolical

    • Chloé 🥕@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      27
      arrow-down
      1
      ·
      1 day ago

      Disclaimer: I have never actually written Rust.

      neither have most of the people advocating for (or against) rewriting stuff in Rust lol

      • boonhet@sopuli.xyz
        link
        fedilink
        arrow-up
        13
        ·
        1 day ago

        I’ll have you know, I’ve started several projects in Rust!

        Only to realize I don’t have time to do unpaid work even if it IS fun.