Revision sheet: Programming Language Paradigms

Course Outline

  1. Paradigm Fundamentals
  2. Paradigm Taxonomy
  3. State and Mutation
  4. Imperative and Declarative Comparison
  5. Code Implementations
  6. Paradigms in Software Architecture
  7. Referential Transparency and Side Effects

1. Paradigm Fundamentals

Key Concepts & Definitions

  • Programming paradigm : A fundamental style, mindset, or philosophical approach for structuring and organizing computer code.

Essential Points

β˜… Must-know

πŸ“Œ A programming language is a tool such as Python, C++, or Haskell, whereas a programming paradigm is the philosophy behind how code is organized and problems are solved.

Further detail

  • Most modern programming languages are multi-paradigm and can support object-oriented, functional, and procedural styles simultaneously.

Memory Hook

Paradigm = programming philosophy

2. Paradigm Taxonomy

Key Concepts & Definitions

  • Imperative paradigm : Focuses on how to compute a solution step by step by explicitly manipulating program state.
  • Declarative paradigm : Focuses on what result is required without specifying the step-by-step execution details.

Essential Points

πŸ“Œ Programming paradigms are divided into two primary branches according to how they handle state and control flow: imperative and declarative.

  • Procedural and object-oriented programming are sub-paradigms of the imperative branch, while functional, logic, and database-query programming are sub-paradigms of the declarative branch.

Memory Hook

Imperative asks how; declarative asks what

3. State and Mutation

Key Concepts & Definitions

  • State : The data stored in memory at a given moment during program execution.
  • State mutation : Changing memory values in place over time during program execution.

Essential Points

  • The imperative paradigm commonly uses mutable state, in which variables change their values in memory, whereas the declarative paradigm uses immutable state, in which data cannot be modified in place.

Memory Hook

Mutable state changes in place

4. Imperative and Declarative Comparison

Essential Points

β˜… Must-know

  • Imperative control flow commonly uses for and while loops, explicit if branching, and jumps, whereas declarative control flow uses recursion, higher-order functions, and pattern matching.

  • Side effects such as writing to disk or modifying global variables are common and expected in imperative programming but minimized or completely eliminated in declarative programming.

Further detail

πŸ“Œ Imperative programs primarily use statements, procedures, and objects, whereas declarative programs primarily use expressions, pure functions, and mathematical rules.

  • Representative imperative languages include C, C++, Java, and Pascal, while representative declarative languages include Haskell, Prolog, SQL, and HTML.

Memory Hook

Steps versus results

5. Code Implementations

Essential Points

β˜… Must-know

  • The imperative C solution for summing odd values in [1, 2, 3, 4, 5] initializes a mutable total to 0, loops through the array, tests each value with a conditional, adds odd values to total in place, and returns the total.

  • The declarative Haskell solution expresses the same task as sum (filter odd numbers), transforming the input with filter and summing the resulting odd values without mutable loops or variables.

Further detail

  • For the array [1, 2, 3, 4, 5], filtering out even numbers leaves 1, 3, and 5, whose sum is 9.

Memory Hook

Loop and mutate versus filter and sum

6. Paradigms in Software Architecture

Essential Points

πŸ“Œ Selecting a paradigm that matches a specific domain can reduce bug density in software systems.

  • Functional immutability can prevent race conditions in multi-threaded systems by avoiding in-place state changes.

  • Modern enterprise architectures can combine object-oriented models for domain entities, functional pipelines for ETL data-stream processing, and declarative markup such as HTML or YAML for user interfaces and setup configurations.

Memory Hook

Match the paradigm to the domain

7. Referential Transparency and Side Effects

Key Concepts & Definitions

  • Referential transparency : A function is referentially transparent when it can be replaced by its result without changing program behavior, provided the same inputs always produce that result and no side effects occur.

Essential Points

β˜… Must-know

  • The function add(x, y) that returns x + y is referentially transparent because, for inputs 2 and 3, it always returns 5 and has no side effects.

  • The function add_with_log(x, y), which prints β€œAdding” before returning x + y, is not referentially transparent because console output is an I/O side effect.

Further detail

πŸ“Œ A database query such as SELECT name FROM students WHERE grade > 15 is declarative because it specifies which data to obtain without describing table scans or memory loops.

πŸ“Œ Incrementing counter inside a while loop is imperative because it explicitly changes program state step by step, whereas defining f(x) = x^2 + 1 is declarative because it states a mathematical relationship.

Memory Hook

Same input, same result, no effects

Synthesis Tables

Imperative Versus Declarative Paradigms

FeatureImperative ParadigmDeclarative Paradigm
Core philosophyTell the computer how to solve a problem step by stepState what result is required
State managementMutable state; variables change values in memoryImmutable state; data cannot be modified in place
Control flowLoops, explicit branching, and jumpsRecursion, higher-order functions, and pattern matching
Side effectsCommon and expectedMinimized or completely eliminated
Primary unitsStatements, procedures, and objectsExpressions, pure functions, and mathematical rules
Representative languagesC, C++, Java, and PascalHaskell, Prolog, SQL, and HTML

Common Pitfalls & Confusions

  1. A paradigm is not the same thing as a programming language.
  2. Imperative programming specifies execution steps rather than only the desired result.
  3. State describes stored data at a moment, whereas mutation describes changing that data.
  4. Minimizing side effects does not mean that every declarative program has absolutely no side effects.
  5. The loop-based implementation is imperative because it explicitly describes the execution steps and mutates an accumulator.
  6. Immutability addresses shared-state modification; it is not the same as merely using functional syntax.
  7. A function that prints to the console is not referentially transparent even if its returned value is deterministic.

Test your knowledge

Test your knowledge on Programming Language Paradigms with 11 multiple-choice questions with detailed corrections.

1. Which option best describes what a programming paradigm is?

2. What is a programming paradigm?

Take the quiz β†’

Review with flashcards

Memorize the key concepts of Programming Language Paradigms with 11 interactive flashcards.

What is a programming paradigm?

A fundamental style or philosophy for structuring computer code.

Programming paradigm

A style or approach for organizing code.

What distinguishes a programming language from a programming paradigm?

A language is a tool, while a paradigm is the organizing philosophy.

See flashcards β†’

Similar courses

Create your own revision sheets

Import your course and AI generates sheets, quizzes and flashcards in 30 seconds.

Sheet generator