Even though terminology is far from standardized, a common way to is categorize major programming paradigms into
- Procedural
- Functional
- Logical
- Object-Oriented
- Generic
You seem to already know what procedural programming is like.
In functional languages functions are treated as first-class objects. In other words, you can pass a function as an argument to another function, or a function may return another function. Functional paradigm is based on lambda calculus, and examples of functional languages are LISP, Scheme, and Haskel. Interestingly, JavaScript also supports functional programming.
In logical programming you define predicates which describe relationships between entities, such as president(Obama, USA)
or president(Medvedev, Russia)
. These predicates can get very complicated and involve variables, not just literal values. Once you have specified all your predicates, you can ask questions of your system, and get logically consistent answers.
The big idea in logical programming is that instead of telling the computer how to calculate things, you tell it what things are. Example: PROLOG.
Object-oriented paradigm is in some ways an extension of procedural programming. In procedural programming you have your data, which can be primitive types, like integers and floats, compound types, like arrays or lists, and user-defined types, like structures. You also have your procedures, that operate on the data. In contrast, in OO you have objects, which include both data and procedures. This lets you have nice things like encapsulation, inheritance, and polymorphism. Examples: Smalltalk, C++, Java, C#.
Generic programming was first introduced in Ada in 1983, and became widespread after the introduction of templates in C++. This is the idea that you can write code without specifying actual data types that it operates on, and have the compiler figure it out. For example instead of writing
void swap(int, int);
void swap(float, float);
....
you would write
void swap(T, T);
once, and have the compiler generate specific code for whatever T
might be, when swap()
is actually used in the code.
Generic programming is supported to varying degrees by C++, Java, and C#.
It is important to note that many languages, such as C++, support multiple paradigms. It is also true that even when a language is said to support a particular paradigm, it may not support all the paradigm's features. Not to mention that there is a lot of disagreement as to which features are required for a particular paradigm.