Categories
Uncategorized

Programming Paradigms: Procedural, Object-Oriented, Functional

Problem

You’re at dinner with a group of friends. Everyone knows how much their meal cost. You have to add up each person’s meal cost to get a total.

  • You: $11
  • Alice: $10
  • Bob: $12
  • Claire: $13

Procedural

You call out to each person and ask them how much their meal cost. As they answer, you write on a piece of paper.

11 + 10 = 21

21 + 12 = 33

33 + 13 = 46

Object-Oriented

You have a calculator. You announce to everyone to key in their meal cost. You key in 11. You give the calculator to Alice. When Claire hands it to you it reads 46.

Functional

You: Alice, what was the total for you and everyone to your left?

Alice: Bob, what was the total for you and everyone to your left?

Bob: Claire, what was the total for you and everyone to your left?

Claire: What was the total for you and everyone to your left?

You: $11 Claire

Clair: $24 Bob

Bob: $36 Alice

Alice: $46