76
@flux_and_solder ·

How long before the borrow checker stops feeling like an argument every day Learning

Six weeks in, coming from ten years of Python and some C. I can write code that works but I spend maybe half my time restructuring things to make the compiler happy, and I never predict in advance which design will be fine. People who got past this: roughly how long did it take, and was there a specific concept that flipped it, or is it just volume of hours?

9 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @borrowck_ben · 10mo ago · 2 replies

    Around three months for me before I stopped being surprised, and the thing that flipped it was learning to decide ownership before writing the struct rather than after. Concretely: for every field, ask who owns this, who needs to see it, and does the seeing outlive the owner. If the answer to the last one is yes, you need an Arc or an index, and you know that before you write a line rather than after the compiler tells you. Once the design carries the answer, the errors mostly stop.

    74
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @flux_and_solder · 10mo ago

      Deciding it up front rather than discovering it is a completely different mental habit from what I've been doing. Going to try that on the next module.

      21
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @attic_server · 10mo ago

    Also worth noting the feeling never fully goes away with self-referential structures and complex async, it just becomes rare and you recognise the shape immediately. Four years in and I still occasionally rewrite a design because of it, I just do it in ten minutes instead of a weekend.

    39
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @grepwitch · 10mo ago · 3 replies

    Two months, and the concept was that a reference is a borrow of a specific thing for a specific window, not a pointer that happens to be safe. Once I read every & as 'nobody may move or free this until I'm done', the rules stopped feeling arbitrary. Also, and I mean this kindly, coming from C is sometimes harder than coming from Python because you have a working mental model that is nearly right.

    63
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @grepwitch · 10mo ago

      Arena patterns aren't dead in Rust, they just become indices into a Vec instead of pointers. Once you make that swap a lot of C-shaped designs work fine.

      37
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @sdcard_sid · 10mo ago

      The nearly-right model thing is very true. My C habits produced exactly the designs the checker hates, all pointers into a big shared arena.

      29
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @yaml_yusuf · 10mo ago

    It's mostly hours, but the hours count for more if you read the error message properly instead of scanning for the line number. They tell you which borrow, where it started and where it ends. I ignored the middle of those messages for my whole first month.

    44
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @scripting_slowly · 10mo ago · 2 replies

    Honestly, six weeks in I'd say clone freely and move on. Clone everything that isn't in a measured hot path, ship the thing, and go back and remove the clones later when you understand the code better. I lost about two months to fighting for zero-copy designs in code that ran twice a day.

    58
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @borrowck_ben · 10mo ago

      Strongly agree with this as a learning strategy. The compiler is teaching you a real constraint but you don't have to solve it optimally on day one.

      33
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report