★ Must-know
📌 A programming language is a tool such as Python, C++, or Haskell, whereas a programming paradigm is the philosophy guiding how that tool structures computation.
Further detail
Philosophy, tool, memory
★ Must-know
📌 The two primary programming paradigm branches are imperative and declarative, classified according to how they handle state and control flow.
Further detail
Procedural and object-oriented programming are sub-paradigms of the imperative branch.
Functional programming, logic programming, and database querying are sub-paradigms of the declarative branch.
HOW versus WHAT
★ Must-know
📌 Imperative programs generally use mutable state, whereas declarative programs use immutable state whose data cannot be modified in place.
📌 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 are common and expected in imperative programming, while declarative programming minimizes or completely eliminates them.
Further detail
Imperative programming uses statements, procedures, and objects as primary units, whereas declarative programming uses expressions, pure functions, and mathematical rules.
Representative imperative languages are C, C++, Java, and Pascal, while representative declarative languages are Haskell, Prolog, SQL, and HTML.
State, flow, effects
★ Must-know
For the array [1, 2, 3, 4, 5], the imperative C solution initializes a mutable total to 0, iterates with an explicit loop, tests each element with a conditional, adds odd elements to total in place, and returns the total.
For the same array, the declarative Haskell solution computes the result as sum (filter odd numbers), expressing a transformation without mutable loops or variables.
Further detail
Loop versus transformation
📌 Matching a programming paradigm to its domain can reduce bug density by aligning the paradigm with the system's requirements.
📌 Using functional immutability in multithreaded systems can prevent race conditions by avoiding in-place state changes.
Choose by domain
📌 The function add(x, y) that returns x + y is referentially transparent because it returns the same result for the same inputs 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.
Same input, same result
Imperative versus Declarative Paradigms
| Dimension | Imperative | Declarative |
|---|---|---|
| Core philosophy | Tell the computer how to solve a problem step by step | State what result is required |
| State management | Mutable state | Immutable state |
| Control flow | Loops, explicit branching, and jumps | Recursion, higher-order functions, and pattern matching |
| Side effects | Common and expected | Minimized or eliminated |
| Primary units | Statements, procedures, and objects | Expressions, pure functions, and mathematical rules |
| Representative languages | C, C++, Java, Pascal | Haskell, Prolog, SQL, HTML |
Teste tes connaissances sur Programming Language Paradigms avec 18 questions à choix multiples et corrections détaillées.
1. Which statement best defines a programming paradigm in terms of code structure?
2. What distinguishes a programming language from a programming paradigm?
Mémorisez les concepts clés de Programming Language Paradigms avec 30 flashcards interactives.
What is a programming paradigm?
A fundamental style or approach for structuring computer code.
What distinguishes a programming language from a programming paradigm?
A language is a tool, while a paradigm is the guiding philosophy.
What is true about most modern programming languages regarding paradigms?
They support multiple paradigms like object-oriented, functional, and procedural.
Importe ton cours et l'IA génère fiches, QCM et flashcards en 30 secondes.
Générateur de fiches