Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

There's no charge for (functional) awesomeness

1,119 views

Published on

Presentation about adopting functional programming as a way of thinking and solving problems by embracing functional traits of languages like Haskell, F#, Scala and Clojure.

Published in: Software
  • Nice !! Download 100 % Free Ebooks, PPts, Study Notes, Novels, etc @ https://www.ThesisScientist.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

There's no charge for (functional) awesomeness

  1. 1. There’s no charge for FUNCTIONAL awesomeness
  2. 2. #CHILLAXDUDE
  3. 3. There’s no charge for awesomeness…
  4. 4. … nor attractiveness
  5. 5. Object Oriented Programming
  6. 6. OH-OH programming
  7. 7. OO History 1967 Simula 1971 Smalltalk 1983 C++ 1985 Eiffel 1995 Design Patterns 1996 JDK 1.0 2000 Javascript 2002 C# 1.0
  8. 8. Most common language?
  9. 9. OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts. https://twitter.com/mfeathers/status/29581296216
  10. 10. Functional Programming
  11. 11. FP is a way of thinking
  12. 12. λ-calculus 1936
  13. 13. Lisp 1958
  14. 14. More memory Boo!
  15. 15. What language you wish you had created?
  16. 16. Syntactic sugar causes cancer of the semicolon Alan Jay Perlis
  17. 17. #streetcred
  18. 18. Venkat Subramaniam @venkat_s
  19. 19. Bob Martin @unclebobmartin
  20. 20. Neal Ford @neal4d
  21. 21. Rich Hickey @richhickey
  22. 22. Martin Odersky @odersky
  23. 23. Scott Wlaschin @ScottWlaschin
  24. 24. Jose Valim @josevalim
  25. 25. #MOAREXPRESSIVE
  26. 26. Functions are first class citizens
  27. 27. Functions can be declared anywhere
  28. 28. Can you do that in Java or C#?
  29. 29. Higher order functions
  30. 30. Functions that take other functions as parameters
  31. 31. Or return functions as results
  32. 32. Can you do that in Java or C#?
  33. 33. Piping
  34. 34. Chaining operations
  35. 35. Passing the result to the next function
  36. 36. LINQ in C# Streams in Java
  37. 37. public bool FindDragonWarrior(List<string> masters)
 {
 var found = false;
 foreach (var master in masters)
 {
 if (master == "Po")
 {
 found = true;
 break;
 }
 }
 return found;
 }

  38. 38. Remove loop private static bool TheNameIsPo(string master)
 {
 return master == "Po";
 }
 
 public bool FindDragonWarrior(List<string> masters)
 {
 return masters.Any(TheNameIsPo);
 }
  39. 39. Local declaration public bool FindDragonWarrior(IEnumerable<string> masters)
 {
 var nameIsPo = new Func<string, bool>(m => m == "Po");
 return masters.Any(nameIsPo);
 }
  40. 40. Tell a story
  41. 41. Meaning is king
  42. 42. Multiple of 3 or 5 public void PrintMultiples(List<int> numbers)
 {
 Func<int, bool> isMultiple = n => n % 3 == 0 || n % 5 == 0;
 numbers
 .Where(isMultiple)
 .Select(n => $"({n}) is multiple")
 .ToList()
 .ForEach(Console.WriteLine);
 } let printMultiples numbers =
 let isMultiple n = n % 3 = 0 || n % 5 = 0
 numbers
 |> List.filter isMultiple
 |> List.iter (printf "(%d) Is multiple")
 F#
  43. 43. Filter Map Print
  44. 44. #MOARCONSISTENCY
  45. 45. Comprehensions
  46. 46. Well known functions
  47. 47. Clear meaning
  48. 48. Work with collections
  49. 49. Lists, arrays, dictionaries, sets, etc
  50. 50. map Converts each element using a fn
  51. 51. reduce Accumulates elements applying a fn
  52. 52. filter Selects only the elements matching
  53. 53. zip Combines two lists into pairs
  54. 54. #HIGHERQUALITY
  55. 55. Null References The Billion Dollar Mistake Tony Hoare
  56. 56. NULL lacks meaning
  57. 57. Print First Master public void PrintMasterName(List<Person> people)
 {
 var master = villagePeople .FirstOrDefault(p => KFMaster.IsMaster(p.Name));
 
 Console.Write($"The master name is {master.Name}");
 }

  58. 58. What’s default?
  59. 59. Short circuit?
  60. 60. Print First Master public void PrintMasterName(List<Person> people)
 {
 var master = villagePeople .FirstOrDefault(p => KFMaster.IsMaster(p.Name));
 
 Console.Write($"The master name is {master?.Name}");
 }
 Short Circuit
  61. 61. Better… still need to check
  62. 62. Something or Nothing
  63. 63. Maybe type
  64. 64. Java 8 Optional
  65. 65. F# Option type
  66. 66. TryFind first multiple let printFirstMaster villagePeople =
 villagePeople
 |> List.tryFind (getName >> isMaster)
 |> Option.iter (getName >> printf "The fst master is %s")
 Only calls the function if there is something
  67. 67. String option != String
  68. 68. How many times have you parsed an int and failed?
  69. 69. What about a customer that does not have a secondary address?
  70. 70. #MOARCONCISE
  71. 71. quicksort :: Ord a => [a] -> [a]
 quicksort [] = []
 quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
 where
 lesser = filter (< p) xs
 greater = filter (>= p) xs
  72. 72. Declarative
  73. 73. Type inference
  74. 74. See more code
  75. 75. Easy to extract common functionality
  76. 76. Pattern matching
  77. 77. let fizzBuzz number =
 match number with
 | i when i % 3 = 0 && i % 5 = 0 -> "FizzBuzz"
 | i when i % 3 = 0 -> "Fizz"
 | i when i % 5 = 0 -> "Buzz"
 | _ -> number.ToString()

  78. 78. #MOARCONCURRENCY
  79. 79. Pure functions
  80. 80. Immutable by default
  81. 81. Same input => Same out
  82. 82. Replace function with the implementation
  83. 83. No side effects
  84. 84. State introduces time as a variable
  85. 85. #MINDBLOWN
  86. 86. Parser combinators
  87. 87. Test data generation and quick check
  88. 88. Railway oriented programming
  89. 89. Monads / Builders
  90. 90. #MOARACTION
  91. 91. Great match with Agile
  92. 92. No magic pill
  93. 93. Fear to change
  94. 94. More fun
  95. 95. Start somewhere
  96. 96. FP is a way of thinking
  97. 97. Testing
  98. 98. Scripting
  99. 99. Small Library
  100. 100. THANK YOU!
  101. 101. The Smartest tool for agile project management http://smartview.io
  102. 102. amir@barylko.com @abarylko http://bit.ly/abarylkoslides http://orthocoders.com http://westerndevs.com
  103. 103. Resources • InfoQ - StrangeLoop 2011 Language Panel http://bit.ly/1l2t5d2 • The joy of functional programming http://bit.ly/1LKTjJE • Functional Programming: What? Why? When? http://bit.ly/1GVZJGN • Oscon 2013 - Functional Thinking http://bit.ly/1kl2QOd • F# for fun and profit http://bit.ly/1Pf1RLk
  104. 104. Photo Credit • Under http://creativecommons.org/licenses/by/2.5/ • Jeremy Keith, Roast beef, http://flic.kr/p/TKUz • Rob Campbell, Field of daisies, http://flic.kr/p/6QJjU4

×