Performing a method on only those objects which will understand it
Andrew C. Greenberg
werdna at mucow.com
Tue Jan 22 05:10:31 UTC 2002
On Monday, January 21, 2002, at 10:50 PM, Noel J. Bergman wrote:
>> Reasonable minds may differ.
>
> Absolutely. Such is often how the best progress occurs. :-)
>
>> the beauty, reusability, maintainability and elegance
>> of the corresponding code ...
>
> ... too often appear to be the first casualties of expedience. Since
> Smalltalk makes trivial such modifications, it takes discipline to
> preserve
> the aforementioned desirable attributes.
I'm not sure I get the tradeoff here. Criticisms were made on some
theoretical bloat derived from adding a single method to a system class
in support of a system tool. The payoff was to repeat duplicated code
throughout the apparatus of the system tool, which according to Fowler
is the worst stink of all. Fowler devotes an entire chapter to the
simplification of conditional statements. An entire section of the
chapter is dedicated to replacing conditionals with polymorphism.
That said, Martin acknowledges that substituting polymorphism for
conditionals that would occur but once is overkill. This was not the
circumstance here, where the original question acknowledged that he
wanted to get his complex conditional expression right before he filled
his code with it. The code was to operate on all Morphs, but no further
information was given.
Hence the obvious refactoring seemed indicated. I acknowledge other
solutions may be indicated, but as between substantial duplication of
complex code in a system-wide utility to operate on all morphs, and
invading a system class with a single method, well my respect to those
who feel so strongly to the contrary, but as I see it: no-brainer. Now,
there are myriad alternative solutions, as I repeatedly noted before,
but it is pointless to speculate without more.
As to the principal question asked, which seemed most interested in the
"best" way to express the conditional, I think that was far more a
symptom of a problem than a request for a solution -- hence my answers
were phrased as they were.
>> Suggest various textbooks that address these smells in greater detail.
>> I'm particularly fond of "Refactoring."
>
> Which one? Fowler, Beck, Brant, et al; or Brown, Malveau, Brown, et al?
I was referring to Fowler. Each of these references criticize fiercely
the use of conditionals. I'm unaware of any reference in that list that
seems as concerned as some here with the horrors of "system class
modification bloat."
More information about the Squeak-dev
mailing list
|