Advertisement

What's the difference?

Started by April 12, 2001 08:38 AM
4 comments, last by Chronoslade 23 years, 10 months ago
I heard this a while back but I can''t remember what it was. I want to know the differences in MSVC++ between procedural, modular, generic, and object-oriented programming. I would like to know the advantages and disadvantages and a short description if possible. Any input would be appreciated! Thanx in advance. "There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
Real quick description...

Procedural: Code is organized in to blocks and functions. Problem solving is done in terms of steps, like a recipe. This allows the programmer to call a single function to do a task. An example would be printf(), which allows you to print formatted statements without coding it over and over again. Procedural also implies structure, meaning that using goto/spaghetti code is strictly limited, if not impossible.

Modular: A modular programming paradigm? I've never heard of such a thing, but usually 'modular' means that you can use the library/source/whatever in different situations without having to much around with it. FMOD, DirectX, and such could be considered modular since you can just "plug them in" to your program and use them.

Generic: I don't know... I think its netscape? (bonus points to anyone who knows where that is from )

Object Oriented: Coding is done in terms of 'objects' or 'things'. Instead of thinking of the steps to complete a task as is done in procedural, thinking is done in terms of objects and behaviors. You might have a "bird" object that can do things like Fly(), Chirp(), Eat(), etc. True object oriented languages allow for things like inheritance, which allows new objects do be derived from existing ones. You could derive 'Hawk' from 'Bird' for example, and give it a new behavior Kill(), while keeping all the other behaviors from 'Bird'.

Bleh.. anyway, this was all done off the top of my head.. I'm sure it contains some innacuracies/ommisions/etc, and doubtless someone will come along and correct them.

Edited by - A. Buza on April 12, 2001 2:47:06 PM
Advertisement
Thanks for the input.

"There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
DirectX is OO not procedural. OpenGL is procedural.

Procedural - Functions: Fire_Rail_Gun();
Modular - Groups of functions work with the same data structres: IntLinkList_Insert(linkedlist*, int)
OOD - Built-in constructs for modular coding and ''polymorphism''.

n = listAvatar.size();
itEnd = listAvatar.end();
for(it=listAvatar.begin(); it!=itEnd; it++)
it->Act();

The listAvatar can contain many different kinds of Avatars, and the ->Act function can be different for each type of Avatar. You can add new types of Avatars without changing this code, and it still works.

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Generic:
Using only the absolute minimum amount of information to construct your program structure. Uses templates heavily. The way STL describes its algorithms in terms of iterators is along the lines of generic programming.

I wish I could think of a good example of generic programming; I remember one of the main parts of it was that your function argument types should be such that only the things your functions are doing are addressed. Like if you were to write an add function, you would write it so that your arguments were addable and assignable (a = b + c) but not require any other attributes.

Look in JOOP (Journal of Object Oriented Programming)--they have an article on generic programming nearly every issue. Most of it makes my head start to hurt on about a microsecond flat. It looks mostly like Ph.D. thesis fodder without practical application (but the same was said for OOP at one time).
(Here is how I understand them.)


Procedural Programming



Procedural programming focuses on the processing. You think of the operations you want, then choose the algorithms and data structures which will implement them. Procedural programming is good for small applications, but suffers from a lack of organization.


Modular Programming



Modular programming focuses on organization. You group related functions and data (implying separation of unrelated functions and data) into modules, then reducing dependencies by hiding data that is irrelevant to the user of such a module. Handles, representations, structures, unions, or classes are often used to provide multiple instances of data.

A good example of a modular programming language is Modula. A good example of a modular API is *drum roll, please* Win32.


Object-Oriented Programming



Object-Oriented programming focuses on the data types, commonly referred to as "objects." You think of the types that you want, and then provide operations for each type. OOP requires user-defined types and frequently uses data hiding, inheritance, polymorphism and a bunch of other techniques.


Generic Programming



Generic programming focuses on the algorithms. You choose the algorithms you want, then generalize them so that they work with a variety of data structures. Generic programming frequently makes use of parameters to specify policy, such as which operator to use in a comparison, as well as compiler-generated code (C++ templates) and strict type-checking.

The C++ standard library (commonly referred to as the STL) is a good example of generic programming.


My Style



I favor modular programming for the grunt work (the benefits should be obvious), and use of the other paradigms for special problems I encounter. The key to programming in C++ is that you choose the paradigm according to the problem; otherwise you'll end up attempting to extend the language using hacks to implement imaginary features "that should be part of the language."

What was that old saying? Oh yeah,

Stick with what you know and travel light; if you only carry a hammer then all problems are nails. - Unknown

Stupid, very very stupid...

Edited by - null_pointer on April 13, 2001 11:32:11 AM

This topic is closed to new replies.

Advertisement