QB Knowledge Base > Technical Articles > Number 2

Coding Techniques

We can call it the art of coding: to code in a way that makes further changes easy. How should we organize our code? In this article we will discuss some of the most important concepts of coding.

Modular Programming
Always write your code modular. It is very important for several reasons. First, independent modules can be used in more than one project. Suppose you have written a program that needs some financial calculations. If you put the code that performs these calculations into one independent module, you may use it in another program without making any changes. Second, splitting your code into smaller parts makes your project more organized. A well-organized project has a great potential in being extended at any time. The third advantage is the ease of both top-to-bottom and bottom-to-top programming in a modular way. Those who prefer top-to-bottom programming can write the main parts of the code in the main module, while only declaring procedures that will be coded in other modules later. Others who want to write their programs in a bottom-to-top way can write independent modules one by one, and because they write related parts together, it is easier to keep the track of your code and have consideration on what you do. After that, they can put the modules together and write their program. Modular programming also makes programming a large project in a team easier. Consider that most of the advantages of modular programming are associated with the modules' being independent. Of course, at least one module in each project cannot be independent. But if all modules are dependent of others, then there's little advantage in modular programming.

All of this, obviously, applies only to medium or large projects that can be splitted into smaller parts. Small projects usually cannot take advantage of modular programming.

In later articles, we will discuss the use of modules in QuickBASIC in detail.

Procedural Programming
In previous part, we talked about using modules. To be structured enough, your code in each module should be divided into procedures. Unlike modules in a project, procedures in a module can use other procedures and in fact this is why they are put in one module. Each procedure should have only one task. This makes coding procedures easier, since it is easier to apply the changes in your code. You change one procedure and the others that use it will function the same way you want. This is the main advantage of procedural programming.

Conclusion
Organizing your code using modules and procedures has a lot of advantages. The chief advantage is the ease of applying further changes or extending the project. Programmers usually want to extend their projects, but they face difficulties because they haven't written their code in an extensible way. So always consider that you may want to extend your project in the future.

By: Homayoon.P.A.
November 14, 2002


Originally posted on Sepent Technologies.