Programming Paradigm
Table of Contents
A fundamental style or philosophy for structuring programs. Paradigms are not language features — they are approaches to decomposing and solving problems. Most modern languages are multi-paradigm, allowing different approaches within the same codebase.
Related: Functional Programming Object Oriented Programming
Imperative — How to do it
Explicit step-by-step instructions that change program state. The program tells the computer how to achieve a result.
Procedural
Organises code into reusable procedures (functions). The simplest imperative style — sequential execution with function calls.
def calculate_total(items): total = 0 for item in items: total += item["price"] return total
Languages: C, Pascal, early BASIC
Object-Oriented (OOP)
Organises code around objects that bundle state (data) and behaviour (methods). Models entities and their interactions. See Object Oriented Programming.
class Order: def __init__(self, items): self.items = items def total(self): return sum(item["price"] for item in self.items)
Languages: Java, C++, C#, Python, Ruby
Declarative — What to achieve
Describes the desired result without specifying the exact control flow. The what, not the how.
Functional
Computation as evaluation of pure functions. Avoids mutable state and side effects. See Functional Programming.
from functools import reduce # Declarative — describe the transformation total = reduce(lambda acc, item: acc + item["price"], items, 0) # Or with map/sum total = sum(item["price"] for item in items)
Languages: Haskell, Erlang, Elixir, F#; features in Python, JavaScript, Rust, Scala
Logic
Programs consist of facts and rules; the runtime finds solutions by logical inference.
% Prolog — facts and rules parent(tom, bob). parent(bob, ann). ancestor(X, Y) :- parent(X, Y). ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y). ?- ancestor(tom, ann). % true
Languages: Prolog, Datalog; used in theorem provers and AI
Query / Database
Describe what data to retrieve — the engine determines the execution plan.
-- SQL is declarative — describe the result, not the steps SELECT name, sum(price) as total FROM orders GROUP BY name HAVING sum(price) > 100 ORDER BY total DESC;
Languages: SQL, SPARQL, Cypher (Neo4j / BloodHound)
Multi-Paradigm
Most practical languages support multiple paradigms — the programmer chooses the best approach for each problem:
| Language | Primary paradigms |
|---|---|
| Python | Procedural, OOP, functional |
| JavaScript | Procedural, OOP, functional |
| Rust | Procedural, functional, some OOP |
| C# | OOP, functional (LINQ), procedural |
| Haskell | Purely functional |
| Prolog | Logic |