R
Roedy Green
I have just rewritten my Arraylist utility Merge class. I noticed
that I had many methods that were all theme and variations. Surely
somewhere in there is a bug that won't surface until an embarrassing
later moment.
Then I remembered my Forth background. You avoid theme and variation
code. You somehow encapsulate it, test the heck out of your tool,
then solve you problem with a high level tool. If a tool is heavily
used in a variety of contexts, bugs will rapidly surface.
So I went back and noticed a general pattern --- the generic ArrayList
combiner. You match two sorted lists then either include or exclude
the matched/unmatched primaries and secondaries.
There are 16 possible combinations of things you might want to do.
Even the true true true true case is useful -- to combine two sorted
lists into one big one more quickly than you could sort the whole
thing.
I gave the common patterns I am using convenience names, like
"allBut", "combine", "update",
Oddly the generic code is actually easier to understand that the
various special cases were. It is certainly easier to proofread.
that I had many methods that were all theme and variations. Surely
somewhere in there is a bug that won't surface until an embarrassing
later moment.
Then I remembered my Forth background. You avoid theme and variation
code. You somehow encapsulate it, test the heck out of your tool,
then solve you problem with a high level tool. If a tool is heavily
used in a variety of contexts, bugs will rapidly surface.
So I went back and noticed a general pattern --- the generic ArrayList
combiner. You match two sorted lists then either include or exclude
the matched/unmatched primaries and secondaries.
There are 16 possible combinations of things you might want to do.
Even the true true true true case is useful -- to combine two sorted
lists into one big one more quickly than you could sort the whole
thing.
I gave the common patterns I am using convenience names, like
"allBut", "combine", "update",
Oddly the generic code is actually easier to understand that the
various special cases were. It is certainly easier to proofread.