exercism / csharp

Exercism exercises in C#.
https://exercism.org/tracks/csharp
MIT License
346 stars 346 forks source link

Object Relational Mapping exercise Task 4 has no hint #1973

Open christian-elm opened 2 years ago

christian-elm commented 2 years ago

For a beginner, a hint here would be helpful here. Manually managing resources is quite a daunting task when having not dealt with it before.

aage commented 2 years ago

@christian-elm Do you have a question on how to implement IDisposable?

@ErikSchierboom There is some info on this in the hints.md file, but not specifically for Task 4. Would it be desirable to duplicate it specifically for this task?

christian-elm commented 2 years ago

@aage No, not specifically a question on how to implement the interface. What tripped me up as a junior was that task 4 aborts a database transaction, but I as the "author" of the code don't have direct control of state - calling Database.Write changes the database to a state, but the method caller calls instance.Dispose() which also changes the state. So I would have liked a hint on how to work around this problem when not having direct control of the state of the data layer.

What I can see in the file isn't relevant enough for Task 4 to be duplicated.

christian-elm commented 2 years ago

Also just for consistency's sake it would be nice that all tasks have their hints (they are always very helpful when you get stuck), or at least the tasks that are required in order to unlock new concepts and exercises.

aage commented 2 years ago

@christian-elm I'm sorry, but I don't understand what is unclear. The instructions mention the Orm class needs to clean up the Database half way through a transaction (Dispose right after Write). The task is to implement this code.

Do you have a suggestion of what a hint might be that would clear this up? Adding hints to the two tasks that have none is easy enough.

christian-elm commented 2 years ago

@aage It might be a bit difficult for me as a novice to explain. What trips me up: in Task 2 I'm instructed to call Database.Write(), which changes the state of the database to DataWritten unless an exception is thrown. So, when the test method calls orm.Dispose(), the state of the database has already changed to DataWritten.

My understanding of the exercise instructions is that this is expected behavior, so: what I fail to understand is how I can prevent the state of the database to change to DataWritten when I have implemented a Database.Write() call in task 2.

If this still doesn't make it clear, perhaps it's better to close this issue. Unfortunately I don't have any suggestions for hints as I have yet to complete the exercise myself, which means I don't yet have a good grip on how to properly implement the IDisposable interface.

aage commented 2 years ago

@christian-elm I don't think you're supposed to prevent the state being DataWritten, I think the whole point is how you clean up when being in the middle of a transaction. Hint: you probably can just call Dispose on the Database. I hope this helps.

Can this issue be closed as far as you're concerned?

aage commented 2 years ago

@christian-elm I've given the code another look, I think I know now what you mean. When calling the database you should Dispose the database when an Exception occurs. This goes for the Write method and all the others (except Dispose). The bad write throws an exception which you can try/catch.

Hopefully this answers your question, sorry for the confusion on my end!

christian-elm commented 2 years ago

@aage I managed to figure it out eventually and solve the exercise. Thanks for sticking with it and trying to help! You can probably close this issue now.

aage commented 2 years ago

@christian-elm Great!

@ErikSchierboom Can you close this issue?