Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Clean code transition - how?

by mstone (Deacon)
on May 03, 2005 at 21:00 UTC ( [id://453731]=note: print w/replies, xml ) Need Help??


in reply to Clean code transition - how?

Consider building another layer of abstraction into your current code.

As I understand your question, you don't want to get stuck searching-and-replacing function names in the code that uses these two libraries. By and large, that means both your brain and your survival instinct are in good working order. ;-)

A set of wrapper functions will let you modify your client code once, then switch between the two different libraries with ease. If your client code presently looks like this:

{...} $some_value = old_parser_function_X (@args); {...}

Swap in a generic function name, and then create a new function which calls the original one:

-- client code -- {...} $some_value = generic_function_X (@args); {...} -- wrapper library -- sub generic_function_X { return (old_parser_function_X (@_)); }

The payoff is that you can now write another wrapper that calls functions from your new parser library:

-- new wrapper -- sub generic_function_X { {assemble a result by calling: new_parser_function_A (@some_args) new_parser_function_D (@some_other_args) new_parser_function_N (@still_more_args) } return ($result); }

and it will work as a drop-in replacement for the old wrapper, even though the two parser libraries have completely different APIs.

Writing a test suite that compares the two wrapper libraries then becomes a one-banana problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://453731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found