-
Notifications
You must be signed in to change notification settings - Fork 519
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
Unidiomatic API in forth
#961
Comments
Fundamentally, you're right. Another approach we could take--since there's no plausible reason for an internal #[cfg(test)]
pub fn stack(&self) -> &[Value] -> { ... } However, we're fundamentally constrained by Exercism's design. Part of the interface contract that Exercism provides is that tests are external to student code: you can do anything you want within You're also right that returning I'd be inclined to respond positively to a PR which changed the interface either by changing the return value to |
Hi @coriolinus! I've tried to apply this change using Cheers, |
Doing a bit of digging, it appears that this is a known and long-standing issue. My inclination at this point is to just drop the conditional compilation of |
I quickly stumbled this issue as well, but avoided to post it here, as it seems slightly different to me from my understanding. I agree with you on the general approach, I personally think exercises are not meant to be perfect and can afford leading students to think more about the idioms of the language and look deeper into its concepts. If I'm not wrong, I remember saying to myself when solving this exercise: "Oh okay, this surely is useless but is meant for the tests.". Obviously, it does not mean every student will necessarily come to this conclusion, but it means some probably will. So I would suggest either @Plecra proposes a PR for a different approach or we close this as I don't feel like radically changing this exercise for a minor detail is a good idea. |
I don't mind leaving this issue open, as it presented two proposals:
The second of those is still a good first issue IMO. I just think that we can eliminate the first from serious consideration. |
Closes #961: returning an owned value for a getter that is used for tests only is a bit silly, so this changes the return type of the `Forth::stack` method from `Vec<Value>` to `&[Value]`. It does not require changing the tests. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
As discussed in #1032, the PR was merged too quickly, so this is to complete the contribution by updating the exercise's example in order to be compatible with the modified unit tests. Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
rust/exercises/forth/src/lib.rs
Lines 19 to 21 in 2d163cf
Rust is designed to enable APIs to use the privacy of their implementation for soundness and stability. An interpreter's stack is rarely relevant to the public API, and (imo) wouldn't be found in a "good" Rust crate. It's an implementation detail.
I believe the issue is in the test structure: Since the state of the stack is an implementation detail, tests for its state are unit tests. Rust handles these using tests in the main crate:
I'm also not a fan of this function signature in the exercise. It asks the user to return an owned vector from a reference to their interpreter. This only gives the user the option to clone whatever data structure they're using to represent their stack (which will typically just be
self.stack.clone()
).As a "hard" task, can students attempting this exercise be expected to have a decent understanding of the language? If they know about existential types and iterators (covered by The Book), I think this API would be far less prescriptive:
The text was updated successfully, but these errors were encountered: