-
-
Notifications
You must be signed in to change notification settings - Fork 369
Simple list with LIFO behaviour #2102
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
Simple list with LIFO behaviour #2102
Conversation
Hello. Thanks for opening a PR on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed. That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link to copy this into a new topic there. Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it. |
When you look at the example, please keep in mind that we should discuss the approach rather than treat it as a code review at this stage. |
@michalporeba I haven't yet found the time to look at this, sorry! |
No problem, @ErikSchierboom, take your time. |
{ | ||
var list = new SimpleLinkedList<int>(2).Add(1); | ||
Assert.Equal(2, list.Value); | ||
var list = new SimpleLinkedList<int>(1, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to first have the student use Add
explicitly.
I wonder if actually we should not even have any constructors, just focus on Add
, Remove
and the IEnumerable
logic. Your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to build this exercise more with more granular steps, perhaps using Add
/Count
or Add
/Remove
first. Definitely Add makes sense to start with.
The constructors are, in my opinion, very idiomatic for .net so it would be good to keep them, but they could be a separate step with some narrative to help understand why.
I'll propose something soon (I hope, if not then next week as I will be mostly offline Thursday to Sunday).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with the constructor is that the tests could force the students to write them before they can even get tests running. Unless we do so reflection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests should follow the TDD style, and with steps they can. The C# track already does it so much better than many other tracks I have tried, and with reflection at our disposal we can easily make it work great leading the student through the exercise step by step.
If you don't mind @ErikSchierboom, I'd like to give it a go, implement something like this so we can talk specific pros and cons on an example.
I like that!
I think it is usually called |
The added challenge is that I see we have three options to implement the spirit of the exercise and keep dotnet ways of doing things Option 1 - be stack-likeThe list behaves like a stack (LIFO) and so we could adopt the stack methods Option 2 - follow list naming and add
|
Personally, my preference would be to go with option 1. I think we'll get the cleanest interface that way. |
The biggest change compared to what is there now, but the cleanest end result. I'll got with that. |
Implementing LIFO, with Count and more standard Push(), Pop() methods to align more with the new standard problem specification and other tracks' implementation
It is not the final version, there is more to do before this PR will be ready for proper review, but the tests should pass anyway
Great! Let me know when it is ready to be reviewed. |
This allows for gradual tests without providing the constructor early in the development
this could be a good starting point for the exercise
@ErikSchierboom I got to the point where I need some help. I think the current code could be a good starting point. Constructors are not needed, the
But because there is no stub for the property Also, while I have added |
Add a stub :) I think the default stub could be
You can remove those. Practice exercises don't yet have tasks associated with them, although we are indeed try to start with that. For now, I'd not have them. |
The stub is in place, tasks removed and some information added to help guide the implementation. The previous version of the instructions stipulated that input will be correct, now this has been removed. As such, and for completness of the solution should we expect that |
Yes please! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
exercises/practice/simple-linked-list/.docs/instructions.append.md
Outdated
Show resolved
Hide resolved
exercises/practice/simple-linked-list/.docs/instructions.append.md
Outdated
Show resolved
Hide resolved
3. Implement `Pop()` method which removes and returns a value from the head. | ||
4. Add a constructor to allow initialisation with a single value, or with an interable | ||
5. Implement the `IEnumerable<T>` interface. For more information, see [this page](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1). | ||
6. Ensure `Reverse()` method is available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not something that students need to implement as they get it for free by implement IEnumerable, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they do it right. If they don't then the test will fail.
exercises/practice/simple-linked-list/.docs/instructions.append.md
Outdated
Show resolved
Hide resolved
exercises/practice/simple-linked-list/.docs/instructions.append.md
Outdated
Show resolved
Hide resolved
…d.md Co-authored-by: Erik Schierboom <[email protected]>
Co-authored-by: Erik Schierboom <[email protected]>
Co-authored-by: Erik Schierboom <[email protected]>
Co-authored-by: Erik Schierboom <[email protected]>
Co-authored-by: Erik Schierboom <[email protected]>
…d.md Co-authored-by: Erik Schierboom <[email protected]>
…d.md Co-authored-by: Erik Schierboom <[email protected]>
…d.md Co-authored-by: Erik Schierboom <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great!
Are you okay with me merging this? |
Yes, please! I'd like to submit more PRs for other things, but it looks like there are many open and it would be good to close them and have perhaps smaller changes to avoid work with rebasing and so on. Sort of limiting the work in progress (WIP). |
That sounds great. |
Discussion on the forum: (link).
The problem: The exercise Simple Linked List (specification) explains simple linked list as something with Last In First Out (LIFO) behaviour. It is at odds with what is currently the reference implementation in C# track, and what is required to pass the tests.
The track's expected behaviour is First In First Out (FIFO). At the same time, the implementation, while technically correct, it is less classic, especially in the context of object oriented language like C#. There is no encapsulation of the list internals which can lead to problems with references should LIFO behaviour be implemented. Imagine the below situation:
That is why the common implementation (examples from other tracks: go, c++, java) uses a container external object encapsulating the linked list logic. As you can see in the provided ode the implementation is actually simpler than doing it without encapsulation.
The solution: What I'm proposing means big changes, but it bring the c# track in line with tracks from languages with similar philosophies while at the same time maintaining the .net / C# feel by maintaining
IEnumerable
, usingAdd(T value)
andRemove()
rather thanPush()
orPop()
. It introduces or exercises the concept without forcing solutions that have significant problems (hanging references).This is not finished product. I have done minimal work on the tests, only enough to make them work with the new structure again. If this is the direction we want to go in, I will work on more comprehensive test suite.
Open questions:
Count()
function in line with the problem spec?or perhaps building on top of(This would not work as iterating over the list would empty it!)IEnumerable
we could use Next()?