5. Programming Paradigms(..continued)
• Two paradigms are largely prevalent
• Procedural (vast majority)
• Object Oriented (occasional)
• Functional (old kid making a come back)
8. Paradigm: snippets
• Find elements of a list
Procedural find(list)
Object Oriented list.find(y)
Functional list.filter(x -> (x == y));
9.
10. Snippets(..continued)
even list.filter(x -> (x % 2) == 0)
odd list.filter(x -> (x % 2) != 0)
prime list.filter(Primes::isPrime)
Multiple of list.filter(x -> isMultiple(x, 4))
11.
12. Building block: Function
• Functions return value vs stack.push()
• Functions are methods which have no side effects vs list.add()
• Functions always return the same value for the same input vs
stack.pop()
• Functions don’t access data in other contexts* vs list.size()
13. Side effects
• Have to be managed
• push():pop()
• lock():unlock()
• allocate():free()
23. Monads
Monad Value
Identity storage
Stream parallelising pipeline
Promise deferring pipeline execution
Optional creates non-null and null pipelines,
provides null safety
Either creates two pipelines, usually happy
path and other path, encapsulates
concerns
Try Creates two pipelines, happy path and
exception path, encapsulates concerns