Ashley Bye wrote:I also think findSpaces could probably be renamed getNeighboursOfSpace(Space space), which means the test name would be getNeighboursOfSpace_returns_2_for_space_at_position_0_0(). What do you think?
N Sam wrote:Writing test code eats up valuable design / development time.
Junilu Lacar wrote:If you think about it, the "position_0_0" part of the name also leaks some implementation details so sometimes it can't be totally avoided. Also, we aren't locked in to these names. We can always change them as we learn more about what the code wants to do.
These are all great questions but I'll hint at my answer with a few more questions:
- Would you have asked these questions if we hadn't stopped to retrospect after writing 6 lines of code?
- Would you have stopped to refactor those test names before proceeding?
- Would you have used your tests to inspire more questions to be asked about your design?
- Or would you have used tests to prove that what you had decided to do was working?
Consider these propositions:
- The code is the design
- Good designs are discovered by experimentation and iteration
- Good designs are flavored with many conversations
- Unit tests are most effective when you use them to drive your design
The point is to try to keep implementation details from leaking out into code that should be more abstract/high-level. A test name should be as abstract/high-level as possible because it summarizes an idea -- we want to convey intent more than detail. The test code will give the details. Later on, we'll be writing unit tests that do focus on implementation details but they will have to be preceded by tests that are more abstract/general in nature.
Junilu Lacar wrote:At some point, we should also discuss the decision to throw away existing code vs. trying to refactor and salvage as much of it as we can. Throwing away a lot of code is sometimes unavoidable but it should be the last resort.
Eduardo Bueno wrote:I've been thinking about it since Ashley posted and isn't it correct to name it space_in_corner instead of space_at_0_0? since the test can also be applied for other corner spaces as well.
Ashley Bye wrote:Ah, so we're not specifically writing unit tests yet, rather tests to make sure the concept works and to guide us towards a decision on how to implement the concept?
Ashley Bye wrote:Although they drive the design, you still end up having to experiment right? Only that as you gain more experience, you know what does and doesn't work in certain situations and the experimentations become more complex and larger in scale as projects increase in size?
Ashley Bye wrote:Which leads me to ask - is an array list of spaces to return the results? Is there a better way I can achieve this? But I also know that I have yet to actually instantiate the world - I have a world object but no spaces in it. So I'm also asking how to I store the information about spaces in the world object? Should I store the spaces in a multidimensional array of Space[width][height]? What other ways could this be done? Can I use an array list of spaces again? Is there another collection that would be better suited? Answering these questions will need to be done before I can then look at further implementing the getNeighboursOf method, but will probably require smaller individual tests to be written to make sure the implementation up to that point is sound.