James wrote:
Hi,
Recently my boss has given me a huge program (10000) lines of code.
The program has be written in an unmaintainable fashion.
It looks like someone who did not know programming has written it.
The program is written in such a fashion that it is a miracle that it is working.
Now, My job is to rewrite the program in a professional fashion.
The problem is where do i start. How to begin ?
Experienced programmers please advice.
Thanks,
James
Try to locate subunits of the program that do one specific task apiece.
Turn those into separately defined functions with suggestive names
(that is, the name should tell you what the function does). Each such
function should have one entry. It is best if it uses a fixed number
of arguments. Each subunit should be no more than a page long. In
fact, they should preferably be no more than a few lines each. If they
are longer, they are doing more than one thing.
This process of breaking out functional subunits with telegraphic names
is the essence of "factoring".
You may need to define structs to facilitate communication between
functions. I have an example of factoring a longish subroutine into
smaller functions that increase the clarity of the whole. You can
find it at
http://www.phys.virginia.edu/classes...ogs/Cprogs.htm
Look at #5 on the list. There is a well-factored ANS Forth version,
an unfactored C version, and a factored version using structs. All 3
have been tested. Although the latter would be considered simplistic by
expert C programmers, several of the frequent posters to this group
held my hand while I did the version with structs. And I needed the
help.
Although your 10K line program (not huge, just moderately large; now
if you had said 100K lines ... ) is not likely to resemble my short
routine for adaptive integration, the techniques used in factoring
might be of help. Good luck.
--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/
"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo".