Function & Recursion
Modular Programming
Modular
programming is the process of subdividing a computer program into separate
sub-programs.
A module is a separate
software component. It can often be used in a variety of applications and
functions with other components of the system. Similar functions are grouped in
the same unit of programming code and separate functions are developed as separate
units of code so that the code can be reused by other applications.
Object-oriented programming
(OOP) is compatible with the modular programming concept to a large extent.
Modular programming enables multiple programmers to divide up the work and
debug pieces of the program independently.
The benefits
of using modular programming include:
- Less
code has to be written.
- A
single procedure can be developed for reuse, eliminating the need to
retype the code many times.
- Programs
can be designed more easily because a small team deals with only a small
part of the entire code.
- Modular
programming allows many programmers to collaborate on the same
application.
- The
code is stored across multiple files.
- Code is
short, simple and easy to understand.
- Errors
can easily be identified, as they are localized to a subroutine or
function.
- The
same code can be used in many applications.
- The
scoping of variables can easily be controlled.
Function
A
function is a set of statements that take inputs, do some specific computation
and produces output.
The idea is to
put some commonly or repeatedly done task together and make a function, so that
instead of writing the same code again and again for different inputs, we can
call the function.
Recursion
Recursion is the process of repeating
items in a self-similar way. In programming languages, if a program allows you
to call a function inside the same function, then it is called a recursive call
of the function.
Although
recursive code more concise it needs:
– More memory consumption – as stack
memory is needed
– Takes longer time, should traverse
through all recursive call using stack


No comments:
Post a Comment