Procedural Programming – Introduction
In essence, Procedural Programming is a programming paradigm. A paradigm is a distinct set of concepts and methods that form a model or pattern. Furthermore, in computer science, a programming paradigm is a way of categorising programming languages based on their attributes.
Traditionally a computer program is a set of logical steps that accepts input, processes that input and produces an output. This is the case with both functional and procedural programming. With procedural programs, the emphasis is on how the data is to be processed through functions, routines or subroutines, rather than focusing on the data itself, as with Object Oriented Programming.
Procedural programming follows a top-down approach. In other words, the logic of the program starts at the top and works downwards. It begins with some high level design and closes off with the lower level development. In most procedural programming languages, a Main() function is written and a variety of sub-functions or routines will be called from that Main () function. The sub-functions are developed as and when they are required.
Due to its’ benefits and wide use, procedural programming is one of if not the most favoured programming paradigms. By following procedural programming, the actual code can be split into smaller modules (the aforementioned functions or procedures) so that parts of the code is easier to reuse and that the flow of execution is from top to bottom. The style of procedural programming is generally easy to understand and implement. Because of this, it is usually taught to programming beginners.
Procedural programming differs from the likes of Object Oriented Programming in a variety of ways:
- As mentioned earlier, with procedural programming, the focus is on how to manipulate data through functions and procedures. Whereas, with Object Oriented Programming, emphasis is put on the structure of data, rather than the logic required to manipulate that data.
- Procedural programming follows a top-down approach. Object-Oriented programming takes more of a bottom-up approach.
- A lot of the time in a procedural program, developers might find it quite complicated to add new data and functions for scaling purposes. With an object oriented program, the addition of new data and functionality is simplified.
- In procedural programming, overloading functions isn’t possible. With object oriented, it is.
- Procedural programming differs from object oriented in that it is not based on the real world.
Procedural Programming – Languages
- BASIC – A high-level procedural programming language.
- C – A general-purpose, procedural computer programming language that supports structured programming.
- FORTRAN – A general-purpose procedural programming language.
- Java – Java is a multi-paradigm general-purpose programming language.
- Pascal – A procedural programming language that supports structured programming and data structures to encourage good programming practices.
- PHP – PHP is a popular general-purpose scripting language that is especially suited to web development.
The Advantages of Procedural Programming
- Coding with procedural languages is generally viewed as easy / simple due to the logical nature.
- Reusability –when a function / procedure / routine has been written once, the code can be reused in any part of the program.
- Procedural programs usually requires less computer memory.
- The top-down approach makes it less complicated to track the flow of execution through the code-base.
- Procedural programming is regarded as the best approach for general-purpose development.
- There are an infinite amount of resources out there about procedural programming, as it was one of the earlier formulated paradigms.
The Disadvantages of Procedural Programming
- Vast program code tends to be difficult to write when procedural programming is used.
- Although pieces of code within a program are reusable, the code is often not reusable outside of that program. Meaning developers might be required to recreate the code if it is needed for use by another program.
- It is rather difficult to relate the procedural paradigm to real-world objects.
- Because the emphasis is on the logic required to manipulate data, issues might arise in certain data-sensitive cases when following the procedural approach.
- In procedural programming, it is difficult to create new data types. This reduces overall extensibility.