Towards a Way of Excellence
Mar 30th, 2010 by GeePawHill
In this latest in the DoubleDawg series, I’m so close I can *taste* it.
The After Code for Step 6 (1228)
Tags: Eclipse, geek joy, Hardcore, Java, Legacy, Refactoring, TDD
Posted in Situated Geekery
Thank you so much for recording this, GeePaw!
Most interesting. Welcome back! Thanks!
I notice that the spike used a slightly different approach than the final implementation: I’d say that the spike emphasized type safety while the “TDD implementation” emphasized reuse. I think it will be interesting to see how this works out over time.
While some people think that refactoring should be driven by failing tests, I think it can be driven entirely by code smells. I’d say that test-driven is only necessary for adding functionality; not for changing implementation (IE: refactoring). Of course it’s never wrong to add tests; it just may not be necessary.
Jeff… True enough about the loss of type safety in the TDD’d version. Not at all sure what that means. I think I just realized that I’d have to have some annotations laying around if I were to keep the type. Since there was nothing actually annotation-specific, I let my deep fundamental laziness take over.
I never refactor from a red bar. I strive, in fact, to always go green-to-green over and over. I think those folks who work otherwise are confusing rewriting and refactoring. — Cheers, GeePaw.
You’re not going to keep ignoring your granddaughter’s complaints about the three ‘getter.getString(“fieldName”)’ calls in a row, are you? “Oww! It hurts my eyes!”, she may say. ;->
(What if there where a ‘fieldName’ method in the FieldGetter class? 😉
(And if FieldGetter is good for the processRegexFieldValidator method, then it might be good for the other 39 calls that look like ‘v.fieldName()’ too. 😉
As an experiment, I extended FieldGetter to be a drop-in replacement for the annotation “v” variables. Then I dealt with Feature Envy by extracting methods and moving them to FieldGetter. Since nearly all the differences between the “process*Validator” methods are due to the different field accessors available on each annotation, and that the null checking logic complements FieldGetter’s handling of missing fields, I was able to move nearly everything over to FieldGetter and inline the “process*Validator” methods into their callers.
The AnnotationValidationConfigurationBuilder class went from 689 lines to 354 lines. FieldGetter grew from 36 lines to 192 lines. Plus the addition of a simple interface (StringFilter) with two implementations.
It’s a heavily reflection-based implementation. It’s shorter, but definitely much trickier. I’m not entirely convinced that it’s the best result possible.
To see my code, start with your “ddd7after.zip” files, and then add in my files (mix in the “src” and “tst” directories) from the “2010-05-09 – ddd7after – JeffGrigg Changes Only.zip” file at http://tech.groups.yahoo.com/group/extremeprogramming/files/Discussion/
I think you’re right, that there is first a refactoring into a type hierarchy, then a pulling back up.
My problem right now is that for the first time in the whole series I *do* have an idea where I want to go. — Geeps
Knowing where you want to go is a problem? Gosh, I wish I had more problems like that! ;->
Note: My solution, above, does not use a type hierarchy. The use of reflection enables it to be very procedural, rather than object-oriented. And I would say that the comments I put in the code indicate code smells. But without a type hierarchy, there isn’t any appropriate place to “hang the code.” Moving in the direction of a type hierarchy sounds like a good idea, to me.
Re: “I’m so close I can *taste* it.”
So does it taste like chicken? ;->
(I did *not* mean that as an insult.)
You have an idea. I’d like to see you run with it! ;->
Ahhh, Jeff. Even if I *thought* you were being insulting, which I didn’t, I’d still think that you’ve carried your weight around this project, thus having certain rights.
On the road right now, and I haven’t prepared my talk at Microsoft (couldn’t resist the brag) that happens on the way home. That has to be my priority this weekend.
*But*, I freely admit to being consumed with guilt over stalling so long on the next episode. I speak at MS, arrive home the 8th of June, leave almost immediately for the first beach week my fam and I have had in five years, *then* I get back home. I swear on my honor as a — nevermind — I swear I will record episode as soon as that beach week ends.
Seriously? Your interest really helps me, so thank you! — Hill
Mail (will not be published)
Situated Geekery © 2017 All Rights Reserved.
Free WordPress Themes | Fresh WordPress Themes