🧠 What are Programming Paradigms?
Programming paradigms are different styles or approaches to solving problems using code. They define how you structure and write programs.
🧠 What are Programming Paradigms?
Programming paradigmsare different styles or approaches to solving problems using code. They definehowyou structure and write programs.
🔥 The Most Common Paradigms:
- Imperative Programming
- Procedural Programming
- Object-Oriented Programming (OOP)
- Functional Programming
- Declarative Programming
Let’s use asimple problemacross all paradigms:
✅Problem: Given a list of numbers, return a new list containing only the even numbers.
Let’s say our input is:
numbers = [1, 2, 3, 4, 5, 6]
1. 🧱 Imperative Programming
“Tell the computerhowto do it, step by step.”
numbers = [1, 2, 3, 4, 5, 6]evens = []for num in numbers: if num % 2 == 0: evens.append(num)print(evens)
- You give detailedinstructions.
- Focus is oncontrol flow(loops, conditionals).
- Very close to how machines work.
2. 🧩 Procedural Programming
“Break the steps into reusable procedures or functions.”
def is_even(n): return n % 2 == 0def filter_even(numbers): evens = [] for num in numbers: if is_even(num): evens.append(num) return evensnumbers = [1, 2, 3, 4, 5, 6]print(filter_even(numbers))
- Still imperative, but organized intofunctions.
- Improves readability and reuse.
- Used in languages like C.
3. 🧱➡️🏠 Object-Oriented Programming (OOP)
“Model everything as objects and classes.”
class NumberFilter: def __init__(self, numbers): self.numbers = numbers def is_even(self, n): return n % 2 == 0 def get_even_numbers(self): return [n for n in self.numbers if self.is_even(n)]numbers = [1, 2, 3, 4, 5, 6]nf = NumberFilter(numbers)print(nf.get_even_numbers())
- Focus is onobjects,encapsulation, andresponsibilities.
- Organizes code as interacting entities.
- Used in Java, C++, Python, etc.
4. 🧠 Functional Programming
“Write pure functions. Avoid state and side effects.”
numbers = [1, 2, 3, 4, 5, 6]# Use built-in functional toolsevens = list(filter(lambda x: x % 2 == 0, numbers))print(evens)
- Emphasizespure functionsandimmutability.
- No state change, no side effects.
- Languages: Haskell, Scala, functional-style Python.
Here’s a morepure functionalexample:
def is_even(n): return n % 2 == 0def filter_even(numbers): return list(filter(is_even, numbers))print(filter_even([1, 2, 3, 4, 5, 6]))
5. 🧾 Declarative Programming
“Tell the computerwhatyou want, not how.”
Example usingList Comprehensionin Python (a declarative-style construct):
numbers = [1, 2, 3, 4, 5, 6]evens = [n for n in numbers if n % 2 == 0]print(evens)
- You describewhatthe output should look like.
- Abstracts away thehow(e.g., loops).
- SQL is a good example of a declarative language:
SELECT number FROM numbers WHERE number % 2 = 0;
🧪 Summary Table
🏁 Conclusion
Programming paradigms are not just theoretical concepts — they shape how youthink about problemsanddesign solutions. By rewriting the same task using different paradigms, you can clearly see how each paradigm emphasizes different principles:
- Imperativefocuses on control and explicit steps.
- Proceduralorganizes logic into reusable functions.
- OOPmodels the world using objects and encapsulation.
- Functionalencourages immutability and clean, side-effect-free functions.
- Declarativelets you express thewhat, leaving thehowto the language or framework.
🔄 There’s no “best” paradigm — each has strengths and ideal use cases. As a modern developer, mastering multiple paradigms allows you towrite cleaner, more maintainable, and more efficient code, and gives you the flexibility to pick the right tool for the job.
