Why do we need Programming Paradigms?

Programming Paradigm Concepts

Eleanor Thomas

Senior Data Analytics Engineer

Why do we need programming paradigms?

  • Different problems are best solved with different approaches
  • Example: Solve a Sudoku puzzle vs. Calculate annual revenue
  • Common goals:
    • Accurate results
    • Reasonable time to run
    • Understandable code
  • Paradigms mean having a standard approach
    • Saves time and effort
Programming Paradigm Concepts

Benefits of modular code

  • Modular code: code that is broken up into reusable sections that can be re-run or reused in different contexts
  • Avoid rewriting identical code
  • Separation of responsibilities: certain sections of code have distinct responsibilities and don't duplicate logic
  • Important from the beginning, not just when the total amount of code becomes large
  • Reduce chance of introducing bugs
  • Save development time in the long run

Clock

Programming Paradigm Concepts

Separation of responsibilities in different paradigms

  • Each paradigm handles separation of responsibilities differently
  • Procedural, functional, and object-oriented programming: broken down into procedures, functions, and objects

Separation of responsibilities

Programming Paradigm Concepts

Modular code example

Original code

sum_values1 = 1 + 2
avg_values1 = sum_values1 / 2

sum_values2 = 3 + 4
avg_values2 = sum_values2 / 2

Modular code

def avg_two_values(x, y):
    sum_values = x + y
    avg_values = sum_values / 2
    return avg_values

avg_values1 = avg_two_values(1, 2)
avg_values2 = avg_two_values(3, 4)
Programming Paradigm Concepts

Let's practice!

Programming Paradigm Concepts

Preparing Video For Download...