3.11. Don't Forget Backward Compatibility
Now that I have stabilized a version of repeated that performs best, I have one more issue to consider: what about all those calls to the twice function? The repeated function (whichever implementation I go with) handles the same requirement as that covered by twice. I would rather not have several different functions floating around in my environment, especially since they duplicate lots of the same logic. For example, if I decide to add yet another kind of case conversion, such as InitCap, I would have to enhance both the twice and the repeated functions. That is a real bummer, from a maintenance standpoint.
I do not, on the other hand, necessarily want to get rid of the twice function. It is already used in a number of programs, some of which are in production. I would much rather leave the calls to twice in place and thereby minimize the disruption to existing code. I need a path that offers backward compatibility while at the same time avoids a maintenance nightmare.
The solution is a direct translation to code of that stated need: keep the header to twice the same, but completely gut and replace its internals with...a call to repeated! This approach is shown here:
CREATE OR REPLACE FUNCTION twice (string_in IN VARCHAR2, action_in IN VARCHAR2 DEFAULT 'N') RETURN VARCHAR2 IS BEGIN RETURN (repeated (string_in, action_in, 1)); END;
I could leave off the third argument of 1, since that is the default and I explicitly designed the function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access