Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

By researching around (books, Wikipedia, similar questions on SE, etc) I came to understand that Imperative programming is one of the major programming paradigms, where you describe a series of commands (or statements) for the computer to execute (so you pretty much order it to take specific actions, hence the name "imperative"). So far so good.

Procedural programming, on the other hand, is a specific type (or subset) of Imperative programming, where you use procedures (i.e., functions) to describe the commands the computer should perform.

First question: Is there an Imperative programming language which is not procedural? In other words, can you have Imperative programming without procedures?

Update: This first question seems to be answered. A language CAN be imperative without being procedural or structured. An example is pure Assembly language.

Then you also have Structured programming, which seems to be another type (or subset) of Imperative programming, which emerged to remove the reliance on the GOTO statement.

Second question: What is the difference between procedural and structured programming? Can you have one without the other, and vice-versa? Can we say procedural programming is a subset of structured programming, as in the image?

enter image description here

share|improve this question

3 Answers 3

up vote 22 down vote accepted

Many of the terms can be reused (often miss-used) about programing languages especially those other than Object oriented ones.

Here are some small descriptions on the terms.

  1. Imperative programming - In good old days, when programming was broadly in assembly, code would have tons of GOTOs. Even higher level languages like FORTRAN and BASIC begun to use the same primitives. These languages or rather programming types where the entire program is a single algorithm. This is imperative style. Understand that one can really write totally bad imperative work even in modern C language as well but it is quite easy to do clean stuff.

  2. Structured and Modular programming - Most often we should be able to use the term interchangeably but with subtle differences. When higher level languages begun to get richer, one realized that all units of work should be broken into smaller tractable parts - that is when functions came into existence and programming became a hierarchy of functions and many at lower level could be re-used.

    • Structured programming is any programming when functionality is divided into units like for loop, while loop, if... then etc block structure.
    • Also, here the a piece of code (function) can be re-used.
    • In modular programming, one can create a physical form of package which are fairly general purpose and re-usable. This is called modules of elements compiled together.
    • So one can hardly see modular programs which are not structured and vice versa; the technical definition is subtly different but mostly structured code can be made modular and other way.
  3. Then came "Object oriented programming" which is well defined in literature. Understand that Object oriented programming is a form of structured programming by definition. The new name for all those function based code which is structured code but NOT object oriented is often called as Procedural programming.

    • So basically structured code where functions (or procedures) dominant over data is called procedural where as class and object based representation is called Object oriented. Both by definition are also modular.

Many people think - all of structured programming (may be skipping Object based) as imperative programming; i guess this is only due to lack of clear definition of imperative programming - but it is wrong. You are doing structured programming when you are not doing much imperative ones! But i can still write a lot of functions as well as lot of goto statement inside C or FORTRAN program to mixup.

To be specific to your questions:

First Question : Pure assembly language is imperative language which is NOT structured or procedural. (having step by step interpretive control flow doesn't mean procedural -but division of functionality into function is what make language procedural).

Second Question : Procedural programming is a FORM of structured programming.


BONUS

share|improve this answer
    
So would you say that procedural programming necessarily is also structured programming, while the opposite is not true (though often the case)? –  daniels Oct 31 '11 at 18:33
1  
Yes, i would say so. –  Dipan Mehta Nov 1 '11 at 3:10
1  
In my answer i have defined imperative vs. structured - where imperative programming is written with just step-by-step execution and is not structured. However, according to some definition there is another classification; this is a classification between Declarative (or functional language) vs. Imperative. Declarative languages allow computation without describing its control flow where as imperative is where explicit control flow (step-by-step) is defined. Based on this classification, Imperative programing, for some can be a super-set of structured. Some don't quite follow that definition. –  Dipan Mehta Nov 1 '11 at 3:14
    
I have a different opinion, with regards to the definition of structured programming. Structured Programming and Modular Programming are not the same thing. Please see the definition at the end of this note. The same link suggests that Assembler ** is a ** structured programming language! Reference for definition of STP:en.wikipedia.org/wiki/Structured_programming – Emmad Kareem –  Emmad Kareem Jan 17 '12 at 5:43
    
Is a "physical form of package"... a file, or a directory/archive of files? (Or is it not, and it's something else.) –  naxa Jun 23 '12 at 18:50

First question: Yes, many pure object-oriented languages qualify. While they have methods, which are very close to functions, they view these methods in terms of messages and do not give them enough weight to call the language procedural.

Second question: The difference is often in a different scope. You can have a function with goto statements all over the place, which will be in procedural style, but not structured programming. On the other hand, most OO languages support and encouraged structured programming, but not procedural programming.

Procedural programming describes the global ordering of the program. Procedural programs are those that are most effectively understood by looking at their call graphs. Structural programming is a local property, it applies to the use of if and while as opposed to goto.

As such, these two properties are disjunct, you can have either one without the other.

share|improve this answer
    
The only litmus test for being Procedural is that the language contain procedures (function or methods) and be Imperative, ie. non-Declarative. This means most OO languages that are not pure functional would be Procedural. –  dietbuddha Oct 31 '11 at 16:15
    
@dietbuddha: By this definition, Haskell would qualify as a procedural language via its use of monads. I'd require a certain deal of reliance on procedures to make a language procedural. –  thiton Oct 31 '11 at 16:23
    
I don't know Haskell that well, but I thought Haskell is a pure functional language because it wraps side effects in Monads. –  dietbuddha Oct 31 '11 at 17:27
2  
Well, some people claim Haskell is not purely functional because it allows any interaction with the outside world (or because a GHC extension, unsafePerformIO allows wreaking havok). Others joke that Haskell is their favourite imperative programming language. But fact is, a very large degree of Haskell code lives cleanly seperated from IO, doesn't use nonstandard loopholes to sneak side effects in, and is purely functional. –  delnan Oct 31 '11 at 17:53
1  
@thiton I disagree. Monads are functional constructs too; they only look imperative due to Haskell's syntax sugar (the "do notation"). When you desugar monads, their functional nature becomes evident. In contrast, OO languages are indeed imperative: at their core they are based on the sequential execution of statements. –  Andres F. Nov 16 '12 at 16:47

most of the popular languages of the past 50 years have been designed around the prevalent computer architecture, called the Von Neumann architecture, after one of its originators, John von Neumann.

These languages are called imperative languages.

In a von Neumaan computer, both data and programs are stored in the same memory. The CPU which executes instructions is separate from the memory. Therefore instructions and data must be transmitted from memory to CPU. Results of operations in the CPU must be moved back to memory. Nearly all digital computers built since 1940s have based on von Neumaan architecture.

share|improve this answer
    
+1 not sure what this has to do with the question, but it's an interesting answer. –  Chuck Conway Nov 16 '12 at 17:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.