[Please do not mail me a copy of your followup]
1. Create an automated acceptance test suite around the existing system
2. Port the existing system before you add new features
3. Use TDD and the automated acceptance tests from 1) on your
replacement system
TL;DR:
When porting legacy code from one language to another, you are
essentially talking about a complete rewrite. Unfortunately, unless
you do this in an automated way, you are likely to introduce many bugs
along the way.
So how do we guard against such bugs, minimize them, and find them as
soon as possible?
First, start by writing an automated test suite around your current
system. Think of these as integration tests, regression tests, or
acceptance tests, but they aren't unit tests. Try to create tests
that surround the major subsystems of your code base. A great tool
for expressing acceptance tests is FitNesse <
http://fitnesse.org>,
which gives you a nice editable wiki as a way of expressing your tests
as tables and allows you to write any additional explanatory notes or
links to images or other files directly in the wiki pages describing
your tests. These keeps the test and all the other information about
the subsystem together.
This automated suite of tests can be run against the existing system
and your replacement system to identify discrepencies between the two.
Given that your original system is FORTRAN 66, it most likely operates
on input files and creates output files. It is very easy to wrap a
test harness around this by creating the input files from the FitNesse
wiki table data, invoke the system under test, and then read the
output files for comparison against the expected results in the
FitNesse wiki table.
Second, try to change only one thing at once. In your followup posts
you described how the desire to port the code was motivated by the
need to more easily extend the existing system with new features.
Don't try to add new features at the same time as you are trying to
capture the existing behavior. Your first goal should be to create
new code that can replace the existing code with no change in
observable behavior.
How far "deep" you want the existing behavior preserved depends on the
organization of your existing system. It may be useful to literally
replace the exsisting FORTRAN 66 subroutines with C++ functions/procedures
that are declared 'extern "C"' so that they can be linked into the
FORTRAN code. However, it could be considerably easier to replace
things one subsystem at a time instead of one function at a time.
Perhaps your FORTRAN code consists of multiple executables which each
do a very specific thing. Each executable can be thought of as a
subsystem to be converted. If your FORTRAN code is a single, large,
monolithic executable, then the subsystem boundaries are going to be
inside that executable. Look for groups of functions that work
together to identify subsystems. It is highly unlikely that every
subroutine interacts with every other subroutine. It is more likely
they are connected in clusters. If you don't know the code well
enough to identify the clusters, use a source code analyzer to
identify the interactions. FORTRAN COMMON blocks are a way that
functions are coupled that is unique to FORTRAN, so don't forget to
check for those.
Third, write your new code using test-driven development. Make your
new code easy to unit test by writing the test first and then satisfy
the test with new code in your replacement module. If you're using
FitNesse for the regression acceptance tests, have a way to run those
against your new system to know that your new system is reproducing
the behavior of the old system. If you kept your subsystem boundaries
relatively high level (e.g. not at the level of individual FORTRAN
subroutines), then you will have more freedom in the C++ that you
write in your replacement subsystem.
--
"The Direct3D Graphics Pipeline" free book <
http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <
http://terminals-wiki.org>
The Computer Graphics Museum <
http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <
http://legalizeadulthood.wordpress.com>