Rust linked list exercise should be tagged "hard"

The rust exercise to roll your own linked list should be marked “hard”. Making a linked list is so hard in Rust that there’s an entire Rust tutorial centered around that one topic. The basic issue is that this is the first exercise where we seriously need to understand the borrow checker, and we need to learn either about mem::replace or Option.take and Option.map, neither of which are mentioned in the readme.

1 Like

I’m not convinced yet. The simple linked list is not a cyclic data structure and doesn’t even require lifetime annotations. The tutorial you linked has singly linked lists only as a sort of warm up, the juicy parts are of course the doubly linked lists. And there is a doubly linked exercise on the Rust track, appropriately categorized as hard.

I wonder if instead, the exercise description could be extended to have more pointers about useful standard library functions like the one you mentioned? Maybe some educational material about the smart pointer Box and recursive data structures?

Thinking further, it may be worth asking where this exercise may fit into an extended syllabus. I definitely agree with you that an exercise can be made much harder or easier, depending on how one is guided to it.

I’m not convinced yet. The simple linked list is not a cyclic data structure

I am not sure why involvement of a cyclic data structure is an important measure of hardness.

and doesn’t even require lifetime annotations.

None of the exercises I’ve done in the Rust track have required lifetime annotations, and I’ve done a few “hard” ones.

Here is evidence that the linked list exercise is hard:

  • The linked list exercise puts the student squarely in front of the borrow checker in a way none of the previous (following the syllabus) exercises come even close to doing. So given the knowlege the student has at the point they do this exercise, it’s hard.
  • Here is a conversation between myself and a friend whose day job is working on the Rust toolchain:
    • Me: I spent last night trying to make a linked list in Rust.
    • Friend: It’s hard … It’s a notoriously hard problem in Rust.
  • The exercise took me days to figure out because I didn’t know about mem::replace. The readme doesn’t mention it. So I’m sitting there for days trying to figure out how to write something as simple as LinkedList::push. The compiler errors don’t point you toward that method so really you’re on your own to Google “Rust linked list” at which point you

The tutorial you linked has singly linked lists only as a sort of warm up

Nevertheless, the tutorial exists… presumably because writing a linked list in Rust is far from obvious for a non-expert.

I wonder if instead, the exercise description could be extended to have more pointers about useful standard library functions like the one you mentioned? Maybe some educational material about the smart pointer Box and recursive data structures?

The key is mem::replace. Without any pointer to that, the exercise is hard. I should mention that at the very end, I learned about Option::map and Option::take which significantly simplified the code I’d written with mem::replace.

I haven’t delved into the rust track. Is this a learning exercise or a practice?

I haven’t delved into the rust track. Is this a learning exercise or a practice?

Having used exercism for a while (20-something exercises done on the Rust track), I haven’t encountered this terminology yet. What is a “learning exercise” versus a “practice”?

In the concepts graph generally concepts are accompanied by a (single?) very straightforward exercise marked with a light bulb (the leftmost ones). Those exercises are the «learning exercises»; the others are «practice exercises».

It seems Simple Linked List is a practice exercise.

I definitely agree with OP that the Rust syllabus doesn’t guarantee in any way that people who come to this exercise know enough not to get stuck.

It seems to be a practice exercise for the structs concept, which has quite a few practice exercises already. I think it might make sense to extend the instructions with some learning material and pull it out into a different concept.

Just marking the exercise as hard is not the best solution in my opinion, simply not knowing what to do is not a fun kind of hard.

Broadly speaking, concept exercises are exercises specifically written alongside concept documentation - syllabus material designed to teach a new concept. Those exercises tend to have everything you need to know to solve the exercise laid out and explained for you. These are tailored to a specific language with all the language-specific bits explained for the student. These are designed to help you learn a new concept, without the expectation that you already know all the language features needed to solve it.

Conversely, practice exercises are typically pulled from the problem specs repo. These are generic (across languages). These do not have any language-specific details and rarely lay out how to go about solving the problem. The practice exercises are not tied to a specific concept. They expect that you already know your way around all the necessary language features and do not discuss what those features are.

I may be asking a stupid question here (being a Python maintainer, and not a Rust maintainer) - but is there a hints.md file for this exercise?

We often make hints files for exercises on the Python track that would be “hard” without pointers. This is the one we made for the Simple Linked List exercise. Maybe a hints file that points at both tutorials on making a linked-list in Rust and also links to helpful methods for solving the problem might be in order here?

I see an instructions.append.md that has some details, but I don’t see a hints file.

That makes sense! I see there is already a concept “Option” on the Rust track. I think OP would’ve had an easier time if some concept already introduced Option::take. My gut feeling is the learning exercise for the “Option” concept would be overloaded if we tried to cram Option::take in there somehow.

What about a new concept “Advanced option” or something like that, teaching Option::take, Option::map and maybe more? The linked list exercise could then be marked as a practice exercise for that concept.