Your SlideShare is downloading. ×
Why you should care about functional programming
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Why you should care about functional programming

2,119
views

Published on

A introductory talk about the benefits of functional programming

A introductory talk about the benefits of functional programming


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,119
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Why you should care about Functional Programming Dhananjay Nene TechWeekend 5 December 18th, 2010
  • 2. What is functional programming about ?
  • 3. Functions = input + transformation + output
  • 4. def add(x,y) : return x + ydef double(x) : return 2 * x
  • 5. NO side effects
  • 6. Unit Testing or Integration Testing when NO side effects ?
  • 7. Benefit 1 : Testability
  • 8. Benefit 2 : Easier Integration
  • 9. All variables are final and are an alias to the result of a computation
  • 10. A variable thus cannot have a different value at different points in time
  • 11. Benefit 3 : Concurrency (no locking)
  • 12. Constructs to easily parallelise operations
  • 13. Benefit 4 : Ability to leverage multicores (if applicable)
  • 14. Higher Order Functions :Functions which take functions as parameters
  • 15. def repeat(f,x) : return f(x,x) double(x) OR repeat(add,x)
  • 16. I like to imagine HOFs as policy injection
  • 17. Brevity
  • 18. public static <E extends Comparable<? super E>> List<E> quickSort(List<E> arr) { if (arr.size() <= 1) return arr; E pivot = arr.getFirst(); //This pivot can change to get faster results List<E> less = new LinkedList<E>(); List<E> pivotList = new LinkedList<E>(); List<E> more = new LinkedList<E>(); // Partition for (E i: arr) { if (i.compareTo(pivot) < 0) less.add(i); else if (i.compareTo(pivot) > 0) more.add(i); else pivotList.add(i); } // Recursively sort sublists less = quickSort(less); more = quickSort(more); // Concatenate results less.addAll(pivotList); less.addAll(more); return less;}
  • 19. qsort1 :: Ord a => [a] -> [a]qsort1 [] = []qsort1 (p:xs) = qsort1 lesser ++ [p] ++ qsort1 greater where lesser = filter (< p) xs greater = filter (>= p) xs
  • 20. Think different :
  • 21. Recursion or Comprehensions instead of Loops
  • 22. Pattern Matching instead of if conditions
  • 23. Pattern Matching instead of State Machines
  • 24. Information Transformation instead of sequence of tasks
  • 25. Persistent Data Structures
  • 26. Powerful concurrency constructs : Actors
  • 27. Software Transactional Memory
  • 28. At what cost ?
  • 29. Retraining the brain: Fixed Cost (Remember OO?)
  • 30. Actual development costs (variable) likely to be lesser. Could not find specific case studies.
  • 31. Why ?
  • 32. Programs are often smaller
  • 33. Have a cleaner expression of intent (what instead of how)
  • 34. Big ball of mud is harder to achieve with pure functions
  • 35. Better future proofing in terms of being able to leverage multicore
  • 36. Once you are able to read code written in functional style, its a lot more enjoyable
  • 37. Faster, better, (cheaper?) and Enjoyable!

×