Programming paradigms are a way of grouping programming languages by what they do. Languages can be in more than one paradigm.

Some paradigms look at the way the code is run, such as allowing side effects, or having to do things in a certain order. Other paradigms look at the way that code is grouped, such as putting code into one or two pieces (or instead, many small pieces). Some other paradigms look at the order and pieces that make the program the way it is.

Programming paradigm

There are two main groups of paradigms, imperative and declarative. A language can be both at the same time.

Programming paradigm

Imperative programming

In imperative programs, programmers give the computer a set of ordered steps that need to be done in order to do something. If someone wanted the computer to draw a cat face, they might give directions like "Draw a circle here, draw two smaller circles there, draw two triangles on top" and so on. Imperative programs sometimes have a lot of side effects.

Programming paradigm

There are two major imperative paradigms, and a lot of the time a language will have both:

StructuredThe computer is given directions that are always in a certain order. Steps like "go back to step 3" (known as goto statements) are not allowed. ProceduralThe program lets the programmer give a name to a list of orders, which turns those orders into a "procedure" they can use later. Most structured languages are also procedural. Object-OrientedIdeas are explained to the computer using objects, pieces of code that have a set of orders they can be given and some information about them.

Declarative programming

In declarative paradigms, the programmer tells the computer what to do instead of how to do it. If they wanted the computer to draw a cat face, they might give directions like "Draw a face, draw two eyes, two ears, and a mouth".

The most well-known declarative paradigms are:

FunctionalMost of the work is done by functions with no side effects. LogicA set of facts are stated, and then one or more "questions" are asked. Event-drivenPieces of code are set to run when certain things happen (like the computer being turned on).

Other paradigms

Some paradigms can be found in both imperative and declarative languages. These paradigms are usually found with one of the above paradigms instead of going on their own.

Parallel: More than one piece of code is run at the same time. Meta: Special things in the language let the programmer change the way the language itself acts.

Overview

Programming languages are grouped by paradigms in the same way that machines might be grouped by what they're used for.

A few languages fit in just one main paradigm, such as:

Smalltalk (object-oriented) Assembly (imperative, but not structured or object-oriented) Haskell (functional) Prolog (logic)

Most languages, though, are in more than one paradigm. Some of the ones that stand out for having more than just one are:

Scala (object-oriented, functional, parallel) Visual Basic (event-driven, object-oriented) Common Lisp (procedural, functional, object oriented, meta) Scheme (functional, procedural, meta) Perl (functional, procedural, meta, object-oriented, event-driven) Python (functional, object-oriented, procedural) Ruby (functional, object-oriented, procedural) Wolfram Language (functional, procedural, generally declarative) Oz (logic, functional, imperative, object-oriented) F# (functional, imperative, object-oriented, meta)

Having more paradigms is not always good. One time that having fewer paradigms can be a good thing is when there is a language that is only functional. A function in one of these languages sometimes does less work (like only going over the parts of a group of things it actually needs to) than it might have to if the language was also procedural.

Many programming paradigms are as well known for the things they do not let people do as for those they do let people do. One time where this is true is functional languages. When a functional language is only or mostly functional, it usually will not allow side-effects. Another time where this is true is structured programming: it is different from normal imperative languages because it does not let programmers use "goto statements" (statements telling the program to go to an earlier step). Because of this and other reasons, people sometimes think new paradigms do not allow enough things. It is sometimes okay for the computer to not let people do things, though: it can help people avoid problems with their code, and let the computer make guesses that so it can run code faster, or even check code for problems before the code runs!