Open Source on IBM i

Modular Programming

Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality. --- from Wikipedia

I think that is a good explanation and a design technique which should be used (probably) always and every time though on different scales.


Each time we use global variables it probably goes against this software design technique and we try to minimize the use of global variables. I say "minimize" because in RPG it is not always possible, f. e. data areas have to be defined globally.

And everybody seem to agree to this concept on this scale because now we don't have to scan all 20000 lines of code if a certain variable is used but only the 100 lines of the procedure. Everyone can see the benefit of it. Impact analysis is made in seconds (or minutes) instead of hours and we don't need any expensive tools for doing it.

Modular at System Level

But for some reason most RPG developers find it ok that a program should access any table regardless of the domain (order, master data, ...). It should read and write data from/to it no matter what failing to see the resemblence to global variables. The table is the global variable in the system everyone has access to from everywhere. So now when we need to make a change to some table what is the scope of the impact analysis we have to do?


Could we have minimized the scope of it: Definitely!

How? Offer access to the data via some API. But by offering some API I don't mean to just add a database layer (serviceprogram/procedure) between your program and the table/data without adding any value to it. Just by wrapping your table access into another layer you have gained nothing. Any change behind the scenes of the API should not automatically lead to a change of the API consumer. If it does then you should think about what you have gained by using the API at all.

Now any change to the table should only require an analysis of the program code of the corresponding domain and not the whole system.

In some cases the scope of the analysis can even be minimized to a single service program which makes it even easier.

What are you talking about?

Many programmers don't realize this because they have written the system themselves or lived in the system long enough to know it. But for everybody new to the system it is really hard to make even the tiniest change. Those systems are really hard and costly to maintain because everybody need to know the whole system.

The database should NOT be your API!

Your situation?

Just ask yourself what do you need to know/analyse if you want to make a change? One procedure? One program? Code of one domain? The whole system?

Tags : Design