next up previous contents
Next: 6.3.1 Functions Up: 6. Real programming Previous: 6.2 Branching   Contents

6.3 Modular programming

Modular programming refers to the idea that programs are easier to read, to write, to debug, and to maintain if they are divided into smaller subprograms. In languages like C and C++, this means making self-contained functions. In Fortran95, this means making functions and subroutines. MATLAB has several ways to divide your programs into individual chunks. The benefits of modular programming are several-fold. First of all, it makes your programs easier to write because individual components can be independently written and tested. Second, it makes the ``main'' part of the code easier to read since long code sections are replaced with simple functions (whose internal code is hidden in another file). This also makes your programs simpler to modify. Third, individual components can be reused in other programs. For example, suppose you wrote a program that accepted data from the keyboard and calculated the average, standard deviation, etc. If the part of the program that calculated the standard deviation was contained inside a separate function, you could reuse that function in another code that needed to calculate the standard deviation. [Need a concrete example here...]

Subsections
next up previous contents
Next: 6.3.1 Functions Up: 6. Real programming Previous: 6.2 Branching   Contents
Gus Hart 2005-01-28