Problem converting a huge Program into small ones

J

James

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
 
M

Mike Wahler

James said:
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.

Can you write a program from scratch in a 'professional
fashion?'
The problem is where do i start. How to begin ?

No offense intended, but if you don't know how to begin,
I suspect you're not the right person for the job.
I've had to do similar work more times than I care
to recall during my career -- it's typically no
simple task, even for folks with much experience.

A few times it was deemed more efficacious to rewrite
from scratch, instead of trying to 'fix' the 'spaghetti
code'. Of course your circumstances might prohibit this,
I don't know.

About all I can offer someone who says 'where do I start'
is to recommend Fowler's book "Refactoring" and similar
works. See http://www.refactoring.com/

BTW your query isn't about C, which is the topic here.
Information on the topic, nature, and guidelines of
comp.lang.c:
http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
Experienced programmers please advice.

My experience combined with the nature of your request
and your apparent lack of direction causes me to advise
the hiring of someone who does know how to do it (best
if (s)he's done it a few times already.)

I'm not saying you're completely incapable of doing this,
but if there are time constraints, well ....

And don't forget the time needed for testing and debugging.

Final note: Don't try to determine what the program does
and how by reading the code. Read the specification.
If there isn't one, tell your boss you need one. You
might write one together, if you both have sufficient
knowledge of the program's purpose. You will have a
much better chance of success if you're coding to a
specific, detailed description.


HTH,
-Mike
 
K

Kevin Easton

James said:
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 ?

Since this a general programming question you'd do well to ask in
comp.programming.

You should start by finding the program specifications, and using those
to construct a series of black-box test cases that test all of the
boundary cases.

Then you can incrementally improve the program, re-running the tests
after each bit of work to ensure that it still meets the specifications.

You will probably need up to 4 or 5 passes of incrementally improving
the entire program before you'll be finished. So perhaps your *first*
step will be making sure that the boss knows it won't happen
overnight...

- Kevin.
 
K

Kris Wempa

Echoing what others have responded, this is really too vague a question for
us to answer. Without knowing the problems in the current programming and
the specifics with which it needs to be converted, it's very hard to give
some sort of advice. I've done this type of work many times and it seemed
to be quite different each time. Now, if you gave more specifics, I might
be able to give some pointers.
 
J

Julian V. Noble

James said:
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/551.jvn.fall01/CiSE_progs/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
(e-mail address removed)
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo".
 
K

Kevin D. Quitt

#1. Don't convert it.

#2. Don't even look at the source code, although it's probably OK to read
the comments.

#3. Get or create a functional specification. Get your boss to sign off
on the spec and, if possible, some kind of acceptance test.

#4. Design the program in a top-down manner, code it bottom-up.

#5. If you are having problems with specific functions, you can look at
the existing code, but don't use it unless it's clean. If it isn't,
create a black box that defines its operation and code the black box.

#6. You might remind your boss: "Good, Fast, Cheap. Pick any two."
 
M

Malcolm

James said:
Recently my boss has given me a huge program (10000) lines of
code.

Now, My job is to rewrite the program in a professional fashion.

The problem is where do i start. How to begin ?
Ask if you have the specification for the program. Probably it doesn't
exist. Ask if someone can draw one up. If they won't, ask how you are meant
to know if your version is bug-free without a spec.
This will all take time.

Then you fire up your C compiler and write a program that performs according
to the specification you have been given.
 
K

Kevin D. Quitt

Ask if you have the specification for the program. Probably it doesn't
exist. Ask if someone can draw one up. If they won't, ask how you are meant
to know if your version is bug-free without a spec.
This will all take time.

Then you fire up your C compiler and write a program that performs according
to the specification you have been given.


Listen to this man; he speaks wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top