26

I have heard several times that every programmer should learn one of each type of language. Now, this is not necessarily true, but I believe it is a good idea.

I've learned a Procedural Language (Perl), but what are the other types?

What are the differences between them and what are some examples of each?

3
  • 8
    You should be aware that there are countless overlapping ways to categorize languages. The most common is by programming paradigm, but even then there are major and minor distinctions, many completely seperate axis, and many languages fall into several paradigms.
    – user7043
    Commented Oct 31, 2011 at 19:34
  • 1
    I'd forget about the categories--if you are really interested in learning from a language I'd suggest both Lisp and Scala, if you can handle those two you've covered a lot of ground.
    – Bill K
    Commented Oct 31, 2011 at 21:13
  • 3
    Peter Norvig's advise: Learn at least a half dozen programming languages. Include one language that supports class abstractions (like Java or C++), one that supports functional abstraction (like Lisp or ML), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), one that supports coroutines (like Icon or Scheme), and one that supports parallelism (like Sisal).
    – legends2k
    Commented Feb 11, 2014 at 8:06

5 Answers 5

36

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.

7
  • 2
    Which category would SQL fall into? Commented Oct 31, 2011 at 22:46
  • @KirkKuykendall SQL would be a specialist, or "little", language. Commented Oct 31, 2011 at 23:22
  • 17
    SQL is a Declarative language. You tell it what you want, it figures out how to get it. ("Logical" languages like Prolog are a different subset of Declarative languages)
    – Izkata
    Commented Nov 1, 2011 at 1:47
  • 3
    Could we have a description of procedural, in order to make the answer more complete?
    – deworde
    Commented Nov 2, 2011 at 13:50
  • 3
    @Dima Nice summary. However, a relatively minor nitpick: "generic programming" didn't came about from the use of templates in C++, and is also very frequently used in functional languages such as Haskell.
    – Andres F.
    Commented Jan 30, 2012 at 1:02
11

Programming languages have a number of mostly orthogonal features; the most prominent one lies in the paradigm or paradigms they support. The wikipedia article covers paradigms exhaustively; the most important paradigms are probably these:

  • Procedural / Structured
  • Functional
  • Object-Oriented
  • Event-Driven and Aspect-Oriented
  • Generic
  • Logic

But languages differ in other ways as well:

  • Typing system (dynamic vs. static typing, and strong vs. weak types)
  • Build process and runtime environment (interpreted, bytecode-compiled, fully compiled)
  • Memory management (manual like C / C++, mandatory automatic garbage collection like Java, optional GC like D, ...)
  • Evaluation discipline (eager vs. lazy; most languages are eager by default, but many provide lazy constructs)
  • Scoping rules (compare how scope works in PHP, Javascript and C, three languages that are otherwise quite similar in terms of syntax)
2

There are several different programming paradigms that are currently in vogue:

  • Object Oriented - VB.NET, C#, Java fall into this category. Code is arranged around objects that have behavior and related data and that communicate with each other by passing messages.
  • Functional - Haskel, Scheme, Lisp and F# fall into this category. Pure functions that do not have side-effects. Think functions like in maths. Often one can extend the language itself through its constructs.
8
  • Are these the only other types?
    – Dynamic
    Commented Oct 31, 2011 at 19:25
  • @perl.j - No, but these are the main ones that see wide spread use these days. See wikipedia - Programming paradigm.
    – Oded
    Commented Oct 31, 2011 at 19:26
  • @perl.j there is also Stack-based: such as Forth and Postscript. Logic: such as Prolog.
    – Jetti
    Commented Oct 31, 2011 at 19:27
  • 2
    And the zeroth type is C ;) Commented Oct 31, 2011 at 19:44
  • The real question is how many of these does a dev need to effectively code most programming problems.
    – JeffO
    Commented Apr 6, 2014 at 14:11
1

Most mainstream languages mix aspects of imperative, functional, and declarative programming. Niche languages tend to be more exotic or introduce interesting new ideas that, for one reason or another, aren't suitable for general purpose programming. Some, by no means exhaustive, examples:

  • Spreadsheet Languages (Excel, Google Forms): Designed to handle tabular data.
  • Array Languages (APL, J): Designed to quickly process multi-dimensional arrays. In J, (+/ % #)&.:*: calculates the RMS of an array. Famous for being concise, notorious for being unreadable.
  • Automation Languages (AutoHotkey, Bash): Designed to streamline common tasks, like filling forms, uploading files, etc.
0

Prolog is a logic programming language and is relatively easy to get started with. It requires a completely different thinking than procedural programming therefore it is good to explore when you are trying to stretch your brain.

If you go to college, you should take a course on Programming Languages as it is geared towards introducing the different types of programming languages and what they are best used for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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