Junilu Lacar wrote:
s ravi chandran wrote:
We can have add return true as a response for a successful add and false for a failure in add product. that way, we will only deal with add and not the products.
Ok, we can explore that option. At this point, I would commit whatever changes I've made so far into source control, like Git or SVN. Then we can either switch off the keyboard so you can drive or I can keep driving and you can navigate me through the changes. What test do you want to write for this API change? Obviously, our current test will have to be deleted or changed.
Junilu Lacar wrote:What about the String parameters for slot and productName? Are you good with these or do you think they should be a different type? Should we consider having fewer parameters? How would that work? Are the other alternatives to the API design that we can consider?
Junilu Lacar wrote:I think you may be getting a hang of the process already. Here are the points I wanted to emphasize:
1. Start with knowing what behaviors you want from the software and state these as "stories"
2. Concentrate on defining a good API first. Delay decisions about implementation details for as long as you possibly can. This may seem to contradict the earlier motivation to choose a story based on its architectural significance but it's not really. It's kind of hard to delay architecturally significant decisions for very long because one definition of architecture is "something that's difficult to change later". The trick is figuring out which decisions are architecturally significant vs decisions that involve implementation details that can be easily changed.
3. Use tests to drive design thinking. Don't just write tests because you can.
4. Focus on simplicity and clarity first. Don't think about performance until you have something that works and is easy to maintain. Premature optimization is the root of all evil.
5. Follow the TDD Cycle (RED-GREEN-REFACTOR) as much as you can. Keep Uncle Bob's Three Rules of TDD in mind.
6. Involve other developers as much as you can. Solo development often leads to code that only that one developer can understand and maintain.
7. Involve system testers as much as you can, as early as you can as well. They can provide valuable input about the testability of the designs that you come up with.
Do you still want to continue with the exercise?
s ravi chandran wrote:Other possible scenario is to add a slot with just the name. then in the next phase, we add the product and its quantity. Like we initialize a vending machine with certain number of slots : slot1, slot2, slot3 etc. and when the vendor is adding the products, he needs to fetch which slot he is adding to and enter the product name and quantity.
s ravi chandran wrote:so, the testability for vending machine will be different now, right?
Junilu Lacar wrote:
s ravi chandran wrote:so, the testability for vending machine will be different now, right?
Yes. We backtrack and start over. Luckily, we have only written a few lines of code and throwing it away is not as painful.
How about you give it a shot. What test would you write to show that we don't have any constructor that does what we have just decided to do?
s ravi chandran wrote:will it be a good concept to first create a skeleton structure for vending machine and then following the user stories we created? from functionality point of view, i think we can again start from add method.
Junilu Lacar wrote:You have to resist the compulsion to follow every little thought that pops into your head before you finish one thing.
Junilu Lacar wrote:
s ravi chandran wrote:will it be a good concept to first create a skeleton structure for vending machine and then following the user stories we created? from functionality point of view, i think we can again start from add method.
That's exactly what we're doing. We are framing out the API. Our discussion has led us away from the add method for now and to the constructor. We should follow through with this. This is another thing about development. You need to FOCUS. You have to resist the compulsion to follow every little thought that pops into your head before you finish one thing. When you say "create a skeleton structure" I imagine you thinking of a bunch of different methods that you think you'll need. Fight that urge. Always start from the tests and always focus on one or two things at a time. I say one or two since it's difficult to isolate everything. There's often another aspect of the design that you have to consider while you're focusing on one thing.
You didn't answer my question about the assertion we should make after instantiating a VendingMachine. How about this test then:
And we'd have this in the production code:
This results in a failing test. What little bit of code can we write to make the test pass?
Junilu Lacar wrote:Again, I want to call your attention to the fact that we only have a few lines of code but we have had a lot of discussion about our options. You have also picked up on a lot of things about TDD that you didn't know when we first started. In real-time, with you and me sitting in front of a computer, this whole conversation would have happened in the span of a few minutes. This is what you don't get from reading books about TDD.
Aside from the threads in these forums where I have done the same thing, one of the few examples I've seen that simulates the experience you get with TDD is this article: http://www.objectmentor.com/resources/articles/xpepisode.htm . Read through that and try to get a feel for the dynamics of the conversation. I've tried the same exercise with other people many times and it never goes the same each time. About the only things that stay true are the need for focus on the API first, following the rules of TDD, and lots of discussion.
s ravi chandran wrote:does this mean, products can be added at any moment, and not when the whole row is empty?
Junilu Lacar wrote:Ok, ignore the parts of my last reply that were made irrelevant with your last post. I still don't see a need to return a boolean from the add method.
Junilu Lacar wrote:In what scenario would add return false then? What if you try to add more items to a tray than it can hold. Like if you had 5 items and you tried to add 5 more items. If the maximum items per tray is only 8, then what happens? Return true still? That doesn't sound right to me.
row and column was looking easier. :-) The logic I was trying was to tell the vendor that quantity limit has reached and more items can not be added. sounds reasonable?A vending machine can have multiple shelves (singular shelf)
Each shelf can have up to 4 trays
Each tray should be filled with only one type of product
Each tray can hold up to 8 items of product
s ravi chandran wrote:row and column was looking easier. :-) The logic I was trying was to tell the vendor that quantity limit has reached and more items can not be added. sounds reasonable?
Junilu Lacar wrote:
s ravi chandran wrote:row and column was looking easier. :-) The logic I was trying was to tell the vendor that quantity limit has reached and more items can not be added. sounds reasonable?
I still don't see the usefulness of a boolean. Also, you want to use terminology that's closer to what the vendor uses. row and column are names that programmers understand but shelf, tray, and product item are things that a vendor is more likely to understand. Programs that use names that reflect the terminology used in the problem domain are easier to understand and maintain.
Consider Paul's rocket mass heater. |