Skip to content

Add exercise reverse-string #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2017

Conversation

coriolinus
Copy link
Member

Used the reverse-string exercise to test the modifications to the exercise generation script; figured there was no particular reason not to finish it and submit the results.

If nothing else, this is an easy exercise for people to start learning about the difference between &str and String, and the natural implementation is a good way for people to start learning about iterators.

@coriolinus
Copy link
Member Author

coriolinus commented Nov 11, 2017

Something to consider: should we add a Rust-specific property reverse_in_place with signature fn reverse_in_place(input: &mut String)? It would add a bit more work for students, but would help really drive home the difference between an always-immutable string slice str and a mutable String. It would also serve as an introduction to the way Rust handles mutable input variables.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is nothing I would change. except maybe to add that reverse in place

@coriolinus
Copy link
Member Author

Just spent some time attempting to implement fn reverse_in_place(_: &mut String), and decided it's not appropriate for this exercise:

  • Implementing this without unsafe requires allocating a temporary String, which defeats the point of modification in place. Worse, students might not already know that it defeats the point of modification in place, and implement it with allocation. We can't really check for allocation in a test, so we'd have taught them bad habits.
  • Implementing this without allocation, with unsafe, requires fancy tricks: mem::swap, mem::replace, mem::uninitialized, and the like. It also introduces the chance to panic if the input includes characters more than 8 bits wide. Given that this is meant to be a difficulty 1 exercise for new Rust students, I think we're better off just sticking to the exercise as it already is.

@coriolinus coriolinus merged commit 8a0ac5b into exercism:master Nov 13, 2017
@coriolinus coriolinus deleted the add-reverse-string-exercise branch November 13, 2017 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants