Fog Creek Software
Discussion Board




Code cleanup with zero breakage of code base

Hello all,

With the recent discussions here, about rewriting or cleaning up code, i have to admit I want to rewrite parts
of my code... its a mess you know :-)

I wrote an API to automate the processes in an Oracle
standard application, writing a customized API using
stored procedures along with some UNIX C-code wich
calls the stored procedures API when different stuff happens. The stored procedure API then populates the tables of the standard application, and calls functions accordingly. Why i want to rewrite parts of the API is,

1) Automation API was written on the learning curve
(not language-wise, but application-data-model-wise)
and some code, altough it is working, is less than perfect.

2) API code has it fair share of ugly workarounds, and
missplaced functionality, (ie. the API knows about certain
limitations of the different systems using it, wich is by definition brokenness IMHO). 

So, my approach to keep breakage to a minimum during
rewrite is simply to keep the old API-calls intact, and
just let them become wrappers of new code:

Lets say a C-program calls a stored procedure in Oracle,
like this:

procedure ugly_and_hackish_api.DoStuff(p1,p2,p3,p4);

procedure ugly_and_hackish_api.DoStuff(p1,p2,p3,p4)
begin
  -- sending p3 and p4 is unessecary since there is a more
  -- effective way of doing things. Do things the right way.
 
    NewAndShinyAPI.DoStuff(p1,p2);
end;

procedure NewAndShinyAPI.DoStuff(p1,p2);
begin
-- Here is the new API functionality.
end;

Hence, the old API will not break, and I will just have to
wrap one of the API functions at a time, to keep the thing
working. When I am done with every function in the API,
I will change the calling C-programs to implement calls to
the new API, and  get rid of the old one.

Any thoughts, and/or experiences doing this, with API
rewrites would be very apprieciated.

Thanks.

Patrik Öhman
Tuesday, January 29, 2002

If you had a GUI application and rewrote it so that it looked the same as the existing application, that would be a rewrite. And what you've described is also a rewrite. Just because you're keeping the same interface, whether it be a GUI or function names and arguments, doesn't mean you aren't rewriting your project.

Lenny Turetsky
Tuesday, January 29, 2002

In my opinion there is a threshold to pass, or not. It's fine to rewrite the innards of an Api IF your happy with the Api.

The Api is the outside and therefore lays down the paradigms and dogmas of your system. So first you must decide on what's not right: the outside or the inside. Because if it's the outside that's not right then any amount of rearranging of the inside is not going to put that right.

Agree?


Cheers,

Nick

Nicolas Reid
Friday, February 01, 2002

*  Recent Topics

*  Fog Creek Home