Procedural Programming
Procedural programming paradigm lays more emphasis on procedure or the algorithm. Data is considered secondary. Data is loosely available to many functions. This paradigm is: Decide which procedure we want; use the best algorithm we can find.
What is Procedural Programming?
Procedural Programming is the one that directly instructs the device on how to finish a task in logical steps. It's like handing the device a manual. This paradigm uses top-down approach and treat data and procedures as two different entities.
Key Features
- Predefined functions: A function which is predefined in the library, sometimes these are called built-in functions. Example of predefined functions is strlen("string") which calculates the length of the string.
- Local Variable: A local variable is a variable that is declared in the main structure of a method and is limited to the local scope it is give.
- Global Variable: A global variable is a varibale which can be used in any part of code and can be accessed by all the functions.
- Modularity: It is like dividing the program into small small groups which have unique tasks but are grouped together to conclude a large task first.
- Parameter Passing: Parameter passing is a mechanism used to pass parameters to functions or procedures. This can be done through 'Pass by value', 'pass by reference', 'pass by name'
Advantages of procedural programming
- Procedural Programming is excellent for general-purpose programming.
- Source code is portable, therefore, it can be used to target a different CPU as well.
- The program flow can be tracked easily.
- The coded simplicity along with ease of implementation of compilers and interpreters.
Disadvantages of procedural programming
- The program code is harder to write when procedural programming is employed.
- Difficult to relate with real-world objects.
- The data is exposed to the whole program, making it not so much friendly.
- Procedural code is often not reusable, which might pose issues in some data-sensitive cases.