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 so that the default would match the current functionality of twice. That is, however, a dangerous approach. What if the default changes? You are much better off being explicit -- especially since I do not really want the default value. I want a single repetition. That just happens to be the default -- today.
Now all of the programs that call twice will work as is -- no changes required. Yet any changes I make to repeated will automatically carry into the twice function as well.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.