This podcast is called “Legacy Coder” but what exactly is legacy code? I talk about my definition of the term in the fifth episode of the Legacy Coder Podcast.
[podcast_ad]
Here’s how many of the old Natural modules I encounter in my day job look like:
DEFINE DATA
LOCAL USING DDMVIEW
END-DEFINEREAD IMPORTANT-DDM BY SUPERDESCRIPTOR
IF IMPORTANT-DDM.FIELD EQ 1
ADD 100 TO IMPORTANT-DDM.FIELD
UPDATE
END TRANSACTION
ELSE
ESCAPE TOP
END-IF
INPUT USING MAP 'OUTPUT'
END-READ
END
Database access, business logic, and the presentation of the results to the user (UI) are all bundled together into a single module. This becomes a maintenance nightmare quickly and is very hard to test because the individual concerns can’t be separated for testing.
This module could be split up into 5 different modules that only do one thing, can therefore be reused in different scenarios, and can easily be (unit) tested:
READ-DATA)PROCESS-DATA)SAVE-DATA)DISPLAY-DATA)Here’s how the refactored main program would look like:
DEFINE DATA
LOCAL USING ARRDATA
END-DEFINEPERFORM READ-DATA ARRDATA
PERFORM PROCESS-DATA ARRDATA
PERFORM SAVE-DATA ARRDATA
PERFORM DISPLAY-DATA ARRDATA
END
In his book Working Effectively with Legacy Code* Michael Feathers shows different ways of introducing automated tests into a legacy code base. He uses C++ in his examples but the underlying ideas can be applied to any other programming language, too.
Robert C. Martin wrote my all time favourite book for software developers: Clean Code*. If you haven’t read it already, grab a copy now and read it from front to back! No matter what programming language you’re using, you will definitely find lots of ways to improve your existing code in here.
In the very first episode of this podcast I talked about how to unit test your Natural application. In my opinion, that’s a very important step in modernizing a legacy code base.
The post What is Legacy Code? – Legacy Coder Podcast #5 appeared first on SOA rocks!.