Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Shopping Cart Kata

35 views
Skip to first unread message

Darren Jones

unread,
Nov 22, 2024, 4:53:00 AM11/22/24
to North West Ruby User Group (NWRUG)
Really loved the session last night, be good to do something similar again (or even a longer coding session on a weekend?) Thanks to Rob for running it!

This is where me and Ste got up to:


All the tests were passing, but we weren't happy with so much logic being in the scan method. Our next move was to move most of that logic out of the scan method, use the total method more and probably create some more methods.

We also weren't completely happy with how the pricing rules were presented and would probably think a bit more about that. The seemed to be described in a deliberately vague way in the kata, so getting the description right for those would help, especially to cover different types of offers.

The next consideration was whether or not to cache more info in the cart. Currently it just keeps track of which items have been added and in what order, but we considered keeping a running total and sub-totals for each item as well.

Be interesting to see what everyone else came up with!

DAZ
ps - Ste recommended this talk by Sandi Metz about refactoring the Gilded Rose Kata

Rahoul Baruah

unread,
Nov 22, 2024, 5:51:15 AM11/22/24
to North West Ruby User Group (NWRUG)
I did a write-up on it on the train home: https://theartandscienceofruby.com/test-driven-development-kata-9/ (plus a quick tidy up of the final code - I'm pretty pleased with how it turned out). 

B

Darren Jones

unread,
Nov 22, 2024, 11:25:55 AM11/22/24
to North West Ruby User Group (NWRUG)
Love yours and Will's solution Baz!

Love the endless functions and really like the way you used defaults to use the same formula even if there wasn't a bundle offer.

DAZ

Tekin Süleyman

unread,
Nov 30, 2024, 11:29:40 AM11/30/24
to NWRUG Group
Thanks for the writeup both. It’s always good to see how different people approach the same exercise. And thanks to Rob for facilitating!

Based on your post Baz I do feel compelled to jump in and defend the smallest-possible-change idea in the exercise. Myself and Nial did our best to stick within those rules and we were pretty pleased with the code we ended up with. There were a couple of things I think that helped keep us on track. One of those things: we’d do the shameless green first, but then would look for obvious refactorings to improve the code once we had green specs before moving to the next spec. Second: we didn’t necessarily follow the specific examples as they were written in the exercise. If the shameless-green solution felt “wrong” (for example because it was hardcoding some logic or values in way that would obviously break with more examples), we’d add a spec to break it in a way that forced us to address the wrongness. I think by doing those two things we were able to shift the code into something more sensible in small increments and keep with the spirit of the exercise.

That’s not to say we didn’t also struggle at times with the slow, incremental steps, or have to suppress a desire to introduce concepts and abstractions before they were strictly necessary. For example we discussed decoupling the price calculation/discount from the checkout itself similarly to the ProductPriceCalculator in your solution, but actually resisted that because the exercise hadn’t specified that there would be more than one type of discount to apply. If it had, I’m confident we’d have naturally arrived at that abstraction going step-by-step.


Far from a perfect solution, and we had a fair few things we wanted to improve (naming, etc) and also to simplify/rework the specs, but ran out of time.

It would have been great to have discuss some of this more in the session, shame the thirst got the better of you and Will before the end ;p

Tekin



-- 
You received this message because you are subscribed to the Google Groups "North West Ruby User Group (NWRUG)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwrug-member...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/nwrug-members/a4e87f6a-ef1e-48f0-955b-5c2318763fafn%40googlegroups.com.

Rahoul Baruah

unread,
Dec 2, 2024, 12:12:30 PM12/2/24
to 'Rob Whittaker' via North West Ruby User Group (NWRUG)
Although Will's reputation precedes him, in his defence, we left early because I had some work stuff to discuss.

And, although I broke the rules of the game, in my defence, I have the short-term memory of a heavy-metal goldfish. So if I don't write out all the clauses from the spec in one go, I forget what I'm doing and spend the next two hours watching Youtube videos about whether an iPad can replace a laptop(*) and how to choose your perfect tactics on Football Manager.

It was a very good exercise though.

B

(*) There are SO MANY videos, and they all say no. Yet I still watch them.


Reply all
Reply to author
Forward
0 new messages