Programming Paradigms

A programming paradigm is an overall style for organizing code, and the same calculator program from the programming-fundamentals topic can be written in any of them without changing what it actually computes — only how that computation is structured. Procedural programming is the style this entire series has used so far: a sequence of function calls that run top to bottom, each one operating on data passed into it, the same way the calculator's `add`, `subtract`, and `divide` functions each take two numbers and return a result with no memory of anything else. Object-oriented programming instead bundles data and the functions that operate on it together into one unit called an object — a `Calculator` object would hold its own running total as internal state and expose methods like `.add(5)` that modify that state directly, which is useful whenever a program needs to track many independent things that each carry their own data, like a game's characters or a word-frequency counter's running tally from the data-structures topic. Functional programming goes the opposite direction from objects: it avoids stored, changing state entirely and builds programs out of pure functions, ones that always return the same output for the same input and never modify anything outside themselves, which makes a function's behavior easy to reason about and easy to test in isolation, echoing the debugging-and-testing topic's assertion that a predictable function is a testable function. Event-driven programming organizes code around responding to things that happen rather than a fixed top-to-bottom sequence: a button click, a message arriving, a sensor reading changing — each registers a handler function that the program's event loop calls whenever that specific event occurs, which is exactly how a terminal shell from the working-with-a-computer topic waits for a command, and how a graphical interface waits for a click, rather than running once and exiting. None of these four paradigms is strictly better than the others, and most real programs mix them: a web server might be organized around objects, respond to requests in an event-driven loop, and lean on small pure functions for the parts that transform data without side effects — the paradigm is a tool chosen per problem, not a rule applied everywhere, and recognizing which style a piece of code is already using is often the fastest way to understand it.

What does the program need to manage?
a sequence of steps, state, predictable transformations, or waiting for things to happen
Procedural
functions run top to bottom on passed-in data
Object-oriented
data and its functions bundled together as state
Functional
pure functions, no stored or changing state
Event-driven
handler functions fire when something happens
Most real programs mix styles by problem, not by rule
recognizing the style in use is often the fastest way to read code
Same Calculator, Two Different Shapes Procedural: functions act on data passed in Procedural add(total, 5) returns new total subtract(total, 2) returns new total each call takes data in, hands data back out no memory between calls — the caller tracks the running total Object-oriented: state lives inside the object Object-oriented Calculator object holds its own total internally calc.add(5) — modifies its own state caller never tracks the total — the object remembers it for itself same math, same answers, two different places the state lives
Functional vs. Event-Driven No changing state at all, vs. nothing but reacting to change Functional add(3, 4) always returns 7 same input, same output, every single time nothing outside the function is read or changed easy to test in isolation Event-driven event loop click key program waits, does nothing, until something happens a shell waiting on a command, a UI waiting on a click — same idea a real program often uses pure functions inside an event-driven loop

Take programming paradigms further

Ask the copilot about this term, or have our engineers assess it against your process.