Jump to content

Procedural code: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
m oops, typo
 
(16 intermediate revisions by 12 users not shown)
Line 1: Line 1:
#REDIRECT[[Procedural programming]]
In [[computer science]], '''procedural coding''' is an [[anti-pattern]] that involves building indivisible, monolithic solutions to problems by not factoring out commonalities. This leads to highly complex dependencies between components of the code. A classic example of this is a function that contains one hundred lines of instructions.

The main casualties of this anti-pattern are:
# Re-use: Since the granularity of the solutions are not very fine, it is difficult to re-apply one solution to another problem.
# Readability: In order to understand the problems being solved it is necessary to step through code while trying to keep track of the complex state of the world.
# Maintainability: Since dependencies are highly complex, it is difficult to make a change and know what the outcome will be.
# Robustness: Since everything depends on everything else, there are an exponentially large number of failure points.

As way of illustration consider the analogy of driving to a destination. The procedural solution is to follow a set of step-by-step driving instructions without using a map. E.g. "turn left at Main Street, go 2 blocks and turn right...". The driving directions are highly context sensitive and of little use to those who do not share the same point of origination and destination. If we lose our place we may need to back trace through the instructions to find out where we are. If an unanticipated detour occurs a lot of unnecessary analysis is required to get back on course. Also, one wrong turn could lead to hours of lost time or the inability to arrive at the destination.

It is impossible to develop a solution without any proceduralism anywhere, the question is where this occurs and how. Most programming paradigms in use today aim to break up the procedures into small re-usable chunks. See [[Object-oriented]] programming for one example of this.

Another paradigm gaining in commercial popularity aims to break the solution up into two independent stages, a declarative and a interpretive stage. The target state is declared in one stage independent of the solution, and the actual processes used to arrive at any given target are left up to the interpreter. In order to handle all possible permutations of processes needed to arrive at the target states that the various declarative stages might desire, the interpreter is forced to break the problem domain down into its natural components for re-use. See [[declarative programming]].

[[Category:Anti-patterns]]

==See also==

[[Spaghetti code]]

Latest revision as of 04:59, 5 August 2006