Two Ways of Thinking

Lesson 1: Two Ways of Thinking

Before you write the first line of any non-trivial program, you've already made a decision โ€” whether you know it or not. You've picked a programming paradigm: a mental model for how programs should be structured. Every paradigm answers two questions:

  • Where does behavior live?
  • How does data move through the program?

Object-oriented programming (OOP) and functional programming (FP) give opposite answers โ€” and both answers are right, in the right context.

OOP's answer: Behavior lives in objects โ€” bundles of state and methods. Data moves by objects sending messages to each other. Your program is a society of interacting entities.
FP's answer: Behavior lives in pure functions โ€” input goes in, output comes out, nothing else happens. Data flows through functions as explicit values. Your program is a pipeline of transformations.

The Spectrum: Imperative โ†’ Declarative

These two answers sit on a deeper spectrum. Imperative code tells the computer how to do something, step by step. Declarative code describes what you want and lets the machinery figure out the steps. SQL, HTML, and regular expressions are declarative: you state the result, not the loop. FP leans hard toward the declarative end.

Imperative โ€” HOW Declarative โ€” WHAT C ยท Java step-by-step JS ยท Python both styles SQL ยท HTML state the result Haskell pure FP Paradigms aren't binary โ€” every language sits somewhere on this line

A (Very) Brief History

  • 1940sโ€“70s ยท Procedural: Fortran, C. Step-by-step instructions, functions that mutate global state.
  • 1950sโ€“70s ยท Seeds of both: Lisp introduces first-class functions (FP). Smalltalk invents objects and messages (OOP).
  • 1980sโ€“90s ยท OOP goes mainstream: C++, Java โ€” "everything is an object" becomes the enterprise default.
  • 2000sโ€“now ยท The FP renaissance: Haskell, Scala, F#, Elixir go production-grade, and FP features (map, reduce, immutability, pattern matching) invade JavaScript, TypeScript, Python, Kotlin, Rust, and even Java's streams.

Why the comeback? Three forces: multi-core CPUs (shared mutable state is the enemy of parallelism), distributed systems (the web is one giant pipeline of transformations), and a testing culture that rewards pure, deterministic logic.

Don't join a cult: Neither paradigm is "correct." They are different tools for different jobs, and the best engineers know both and choose per problem. This course teaches you both โ€” FP first (Lessons 2โ€“5), then OOP (Lesson 6), then the head-to-head (Lesson 7) and a practical decision framework (Lesson 8).

๐Ÿง  Knowledge Check

1. In the OOP mental model, a program is best described as:

2. Which statement is true of declarative code?

3. Why has functional programming seen a renaissance in the last two decades?

Further Reading