Study Atlas › Computer Science › Programming languages

Programming paradigms

Styles of programming: imperative, object-oriented, functional and logic.

Edited by Alex C, EduAlx · Sources cited below

Explanation

Imperative/procedural (FORTRAN, Backus 1957; C, Ritchie 1972) changes state step by step. Object-oriented (Simula 67, Smalltalk by Kay; C++, Java, Python) bundles data and behaviour. Functional (Lisp by McCarthy 1958; Haskell) uses pure functions and immutability. Logic (Prolog) states facts and rules. Hopper's work led to COBOL and compilers.

Example

Summing squares: a for-loop (imperative) versus sum(x*x for x in xs) (functional style).

Code

class Account:
    def __init__(self, owner, balance=0):
        self.owner, self.balance = owner, balance
    def deposit(self, amt):
        self.balance += amt
        return self.balance

How it works, step by step

  1. Pick a model of computation
  2. Express problems in its terms
  3. Use language features (classes, closures, rules)
  4. Combine paradigms where helpful

Open the interactive page with diagrams →

People behind it

References

  1. J. McCarthy, Commun. ACM 1960, 3, 184–195.
  2. O.-J. Dahl, K. Nygaard, Commun. ACM 1966, 9, 671–678.

Textbooks

Related topics

CompilersPublic-key cryptography (Diffie–Hellman, RSA)Machine learningInformation theory and entropyNeural networks and backpropagationWorld Wide Web, HTTP and HTMLTransformers and large language modelsComputer networks and the TCP/IP modelArtificial intelligence: search and the Turing testRelational databases and SQL