Skip to content
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

brackets: simplify required interface #620

Merged
merged 1 commit into from
Aug 16, 2018

Conversation

Emerentius
Copy link
Contributor

I'm just going to quote Peter Tillemans' post from the slack channel. He put it very nicely.

Peter Tillemans [11 août à 23 h 35]
Regarding the Brackets exercise, the way the challenge is made, the student is forced to use an object-like interface where you have to initialise the 'object' before calling a method on it. This 'object' ends usually up with either the result of the brackets balance or the input text or some intermediate value of the data transformation pipeline. This challenge lends itself well to a purely functional solution. I also feel it pushes students to use stateful solutions where none are warranted. (Actually @mawis pointed this out originally).

The hint in the Readme points students towards using lifetimes, but most just accept the impl From<&'a str> for Brackets as is. They don't work with lifetimes themselves, they only conform to the interface.

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.

I could suggest taking a look at #178 to see why it was written the way it is, but even without looking at it, I know I prefer the interface proposed in this PR since it is less restrictive. Behind the scenes, the student may still submit an implementation that creates a struct, if desired. This is exemplified by the fact that the example does just that. I prefer to give the choice to the student, so I want this change to be enacted.

Please see my note about the version change, to be dealt with before merging.

@@ -1,88 +1,88 @@
extern crate bracket_push;

use bracket_push::*;
use bracket_push::brackets_are_balanced;
Copy link
Member

Choose a reason for hiding this comment

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

note: If the crate name were brackets, I would have wanted the name to be brackets::are_balanced to avoid repetition. However, looks like we are using bracket_push. So I think brackets_are_balanced has to be the name.

It can be worth a discussion whether to change bracket_push (why is it even called bracket-push??? exercism/problem-specifications#693 ) but this PR does not need to depend on it.

@@ -1,3 +1,3 @@
[package]
name = "bracket-push"
version = "1.2.0"
version = "1.3.0"
Copy link
Member

Choose a reason for hiding this comment

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

this should not change until the test cases match https://github.com/exercism/problem-specifications/blob/master/exercises/bracket-push/canonical-data.json 1.3.0. It should go in a separate PR.

Copy link
Contributor Author

@Emerentius Emerentius Aug 14, 2018

Choose a reason for hiding this comment

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

Ah ok, so that's what it's used for. Prescribed test cases also affects two of my other PRs which are trying to add more.

@Emerentius
Copy link
Contributor Author

I've reverted the change to the version.

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.

I found one more note about the variable name, perhaps we can get that changed before merging? awaiting your comment on it.

After that, I don't see anything else I suggest to change, so once I get that I'm going to Approve. I don't know how many downloads this exercise gets daily but I hope to be snappy about this one. So once someone other than me Approves, or if nobody else does then 48 hours since PR submission?

pub fn are_balanced(&self) -> bool {
unimplemented!("Check if your Brackets struct contains balanced brackets");
}
pub fn brackets_are_balanced(_string: &str) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

I understand that the leading underscore is to say it is OK that it is unused.

I would like to suggest instead the model established in #438 - call it string and reference it in the unimplemented message. The benefit of the approach is that it avoids a potential student misunderstanding, thinking that the variable should remain named _string.

Otherwise, this will fall under #476 which asked us to remove all instances of variables with leading underscores

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that sounds reasonable. It felt wrong to put it there in the first place to get past the (denied) warning.

The Brackets struct has a single purpose: To allow `is_balanced` to be
called. It forces an object-style without any advantages over a simple
function.
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.

Everything seems good to me. 48 hours from submission is about 24 hours from now. Or, if a second person Approves then let's merge it sooner.

@petertseng petertseng merged commit 265896d into exercism:master Aug 16, 2018
@petertseng
Copy link
Member

Thanks!

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