Jump to content

Procedural code: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Marudubshinki (talk | contribs)
No edit summary
Crenner (talk | contribs)
m include programming in oop link
Line 11: Line 11:
Note that even if a program is not using [[Object-oriented|objects]], it does not inherently fall into this trap; likewise programs that use objects can also suffer from the same maladies as procedural software. The anti-pattern only occurs if the modules of the program are not factorable.
Note that even if a program is not using [[Object-oriented|objects]], it does not inherently fall into this trap; likewise programs that use objects can also suffer from the same maladies as procedural software. The anti-pattern only occurs if the modules of the program are not factorable.


It is impossible to develop a solution without any proceduralism anywhere using today's computer architectures, the question is where this proceduralism 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.
It is impossible to develop a solution without any proceduralism anywhere using today's computer architectures, the question is where this proceduralism 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]].
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]].

Revision as of 17:10, 13 December 2005

In computer science, procedural coding is an anti-pattern that involves solving a problem by incrementally taking somewhat vague steps towards a perceived solution potentially without a full analysis of the desired goals or problem domain. This linear approach often has the effect of producing a monolithic, error prone and un-reusable solution. A counter approach is object-oriented programming. The polar opposite approach to proceduralism is declarative programming, which starts with the goal and works backwards to find a solution previously conceptualized.

By way of illustration, consider the analogy of driving to a destination. The procedural solution is to produce 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.

The main casualties of this anti-pattern are:

  1. Re-use: Since the granularity of the solutions are not very fine, it is difficult to re-apply one solution to another problem.
  2. 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.
  3. Maintainability: Since dependencies are highly complex, it is difficult to make a change and know what the outcome will be.
  4. Robustness: Since everything depends on everything else, there are an exponentially large number of failure points.

Note that even if a program is not using objects, it does not inherently fall into this trap; likewise programs that use objects can also suffer from the same maladies as procedural software. The anti-pattern only occurs if the modules of the program are not factorable.

It is impossible to develop a solution without any proceduralism anywhere using today's computer architectures, the question is where this proceduralism 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.

See also