Skip to content

reverse-string: Update function template to use a variable name instead of an underscore #438

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 2 commits into from
Mar 2, 2018
Merged

Conversation

cbzehner
Copy link
Contributor

Basically as-titled. It took me an embarrassing amount of time to figure out how to reference the _ in the current function template (i.e. change it to something else). I've really enjoyed the Rust track so far, just trying to help clarify what I found confusing. 😄

I tried to make the minimum number of changes here and ensured that _test/check-exercises.sh was able to validate the reverse-string exercise before submitting.

@coriolinus
Copy link
Member

@cbzehner I'm not inclined to merge this as is; as I explained here, one of my goals as a track maintainer is to ensure that the stubs compile without warning as much as possible. Adding an unused variable to a function works against that goal.

However, I can see how the use of the underscore here might be confusing to someone new to the language. In my mind, this is a documentation issue. I'd like you to update this PR with some subset of the following changes:

  • Add a section to .meta/hints.md explaining what underscore variables are and why they exist, and use configlet to regenerate the README from that. (Stack Overflow thread on this here.)
  • Add an inline comment to the stub explaining underscore comments somewhat more briefly.
  • If you feel that keeping a variable name in the stub is helpful, name it _input instead of input.

@cbzehner
Copy link
Contributor Author

That's good feedback, thanks! Keeping the code warning-free seems like a reasonable goal here. How would you feel about passing the variable to unimplemented initially in order to silence the unused variable warning?

Something like:

pub fn reverse(input: &str) -> String {
    unimplemented!("Write a function to reverse {}", input);
}

@coriolinus
Copy link
Member

Does that work? I've never seen unimplemented!() used like that, but if it compiles, I wouldn't object to that approach.

@ijanos
Copy link
Contributor

ijanos commented Feb 26, 2018

It works! I'm surprised but I like this approach.

Copy link
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @cbzehner!

There are no pending change requests from anyone, so unless something is discovered in the interim, I'll plan to merge this on 2 March. If after that date I still haven't, please feel free to ping me to remind me.

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.

This question won't affect whether this PR should be merged: To what extent would we like similar changes to be made on any other exercises that contain a non-empty stub?

@coriolinus
Copy link
Member

coriolinus commented Feb 27, 2018 via email

@ijanos
Copy link
Contributor

ijanos commented Feb 28, 2018

I think the underscore is arcane knowledge for a beginner, so I would love getting rid of it.

I prefer using a proper variable name and reference it in the unimplemented! macro so it will compile without warnings. The intention is clear and we can provide good variable naming examples.

I do not like the _name naming in a stub because we use it for warning suppression but I don't think this is obvious for a student. They can use that name without removing the underscore and solve the exercise with thinking the underscore is some weird rust thingy.

At least using a single underscore as a variable name may have the "this place is intentionally left blank" impression and it forces the student to change it because it is a compile error to use underscore as a variable.

@cbzehner
Copy link
Contributor Author

Would y'all mind if I open an issue for updating the stubs?

I think it would be great to have it open and tag it as "beginner-friendly" to track which ones need to be updated and provide an entry point for people to get involved.

@coriolinus
Copy link
Member

@cbzehner I would not mind that at all, particularly if you did the work of tracking down which exercises currently use underscores in the stubs.

@coriolinus coriolinus merged commit 7050814 into exercism:master Mar 2, 2018
@cbzehner
Copy link
Contributor Author

cbzehner commented Mar 2, 2018

Thanks y'all for all the feedback and help with this request. I know it's just as much work to review as to write this but I've learned a lot in the process and really appreciate it!

@cbzehner cbzehner deleted the reverse-string branch March 2, 2018 21:47
Baelyk added a commit to Baelyk/rust that referenced this pull request Mar 17, 2018
Resolves exercism#438

Changed the parameter to `input`, and uses it in `unimplemented!()` to silence the unused variable warning.
@Baelyk Baelyk mentioned this pull request Mar 17, 2018
9 tasks
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.

4 participants