Programming Paradigms

How the major programming paradigms organize programs and when to use each: imperative and declarative styles, pure and higher-order functions, closures, recursion, immutability, laziness and pattern matching, objects, encapsulation, dynamic dispatch, inheritance, composition and the SOLID principles, design patterns in object-oriented and functional form, static, dynamic, structural and generic type systems with mypy and Rust, exceptions versus result types, threads, processes, races, locks, deadlock and message passing, async and await, event-driven, logic and reactive programming, ending in a multi-paradigm design capstone, with examples in Python, Java, Rust and Go.

CMPUT-274 Year 2 3 credits 12 lessons · 5 h 57 min

Offered by HSM University · Computing Science

What you'll learn

  • Explain what a programming paradigm is, distinguish imperative, declarative, functional, object-oriented, logic, concurrent and event-driven styles, and recognize each in code written in multi-paradigm languages.
  • Write pure functions, identify side effects and explain referential transparency, and use first-class and higher-order functions, closures, partial application and composition to replace loops with pipelines.
  • Use structural recursion, explain tail calls and Python's recursion limit, work with immutable and persistent data, build lazy pipelines with generators, and model data with algebraic data types and pattern matching.
  • Design classes that encapsulate state behind interfaces and maintain invariants, explain identity, aliasing and dynamic dispatch, and use subtype polymorphism and duck typing.
  • Apply inheritance, abstract base classes, interfaces and sealed hierarchies correctly, respect the Liskov substitution principle, prefer composition where appropriate, and apply the SOLID principles.
  • Recognize and implement the strategy, observer, command, factory and decorator patterns in object-oriented and functional forms, and judge when a pattern adds needless complexity.
  • Compare static and dynamic, strong and weak, and nominal and structural typing, use Python type hints with a static checker, and explain generics, variance, option types, inference and ownership types.
  • Distinguish expected failures, environmental failures and bugs, and handle them appropriately with exceptions, result and option types, validation at boundaries, assertions and contracts.
  • Distinguish concurrency from parallelism and CPU-bound from I/O-bound work, use threads and process pools, identify race conditions by reasoning about interleavings, and explain the effect of the GIL and the free-threaded build.
  • Protect critical sections with locks, coordinate threads with queues and other primitives, analyse and prevent deadlock using the Coffman conditions and lock ordering, and design concurrency with channels and actors.
  • Write event-driven and asynchronous programs with async and await while avoiding blocking calls, explain unification and backtracking in logic programming, and build dataflow and reactive pipelines.
  • Design a multi-paradigm system by mapping requirements to paradigms, using a functional core with an imperative shell, parsing at boundaries, encapsulating stateful entities and parallelizing independent work.

Course content

12 lessons · 5 h 57 min total · final exam

  1. 1 What a programming paradigm is 30 min · quiz
  2. 2 Functional programming I: pure functions and higher-order functions 31 min · quiz
  3. 3 Functional programming II: recursion, immutability, laziness and pattern matching 32 min · quiz
  4. 4 Object-oriented programming I: objects, classes, encapsulation and polymorphism 29 min · quiz
  5. 5 Object-oriented programming II: inheritance, composition, interfaces and design principles 29 min · quiz
  6. 6 Design patterns across paradigms 29 min · quiz
  7. 7 Types and type systems 29 min · quiz
  8. 8 Error handling and program robustness across paradigms 31 min · quiz
  9. 9 Concurrency I: threads, processes and shared state 28 min · quiz
  10. 10 Concurrency II: synchronization, deadlock and message passing 29 min · quiz
  11. 11 Asynchronous, event-driven and other paradigms 30 min · quiz
  12. 12 Capstone: choosing and combining paradigms 30 min · quiz
  13. E Final exam 20 questions

Requirements

Recommended background. You can start any course at any time.

Description

How the major programming paradigms organize programs and when to use each: imperative and declarative styles, pure and higher-order functions, closures, recursion, immutability, laziness and pattern matching, objects, encapsulation, dynamic dispatch, inheritance, composition and the SOLID principles, design patterns in object-oriented and functional form, static, dynamic, structural and generic type systems with mypy and Rust, exceptions versus result types, threads, processes, races, locks, deadlock and message passing, async and await, event-driven, logic and reactive programming, ending in a multi-paradigm design capstone, with examples in Python, Java, Rust and Go.

Part of the Science stream, typically taken in year 2.