home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

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:

   (string_in IN VARCHAR2, action_in IN VARCHAR2 DEFAULT 'N')
   RETURN (repeated (string_in, action_in, 1));

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.

Previous: 3.10 Choosing the Best Performer Advanced Oracle PL/SQL Programming with Packages Next: 3.12 Obliterating the Literals
3.10 Choosing the Best Performer Book Index 3.12 Obliterating the Literals

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference