SlideShare a Scribd company logo
OOP makes code understandable by encapsulating 
moving parts. FP makes code understandable by 
eliminating moving parts. 
Riccardo Terrell – Silicon Valley Code Camp 
2014 
— Michael Feathers 
(author of Working with Legacy 
Code)
Agenda 
History and influence of Functional Programming 
Functional vs Imperative Programming 
What is Functional Programming 
Functional Programming characteristics 
Why Functional Programming
History 
LISP 
ISWIM 
APL 
ML 
1973 
FP 
1958 1966 
1962 
1977 
2005F# Clojure 
1988Haskell 
Scala 2003 
2007 
Ocam 
1996 
l 
1930 
-ish 
1986Erlang 
λ
Functional Programming 
Influence 
 Continue Evolution of GC – Lisp ~1958 
 Generics – ML ~ 1973 
 In early 1994, support for lambda, filter, map, and reduce was added to 
Python 
 List comprehension - Linq in C# 3.0 and Java 8 
 First-class functions were also introduce Visual Basic 9, C# and C++ 11 
 Java 8 supports lambda expressions as a replacement for anonymous 
classes 
 Is Lazy Evaluation is part of the main stream languages such as C# 
 Type Inference, example is the “var” keyword in C# 
Programming in a functional style can also be accomplished in languages that aren't
Objectives 
 Use functions as building block and composition to solve 
complex problem with simple code 
 Immutability and Isolation are your best friends to write 
concurrent application 
 Concurrency and reliability are becoming more and more required, 
FP will help you! 
 Functional and imperative styles should NOT stand in opposition 
… 
… they should COEXIST 
 Poly-paradigm programming is more powerful and effective 
than polyglot programming
FP vs OOP the Paradigm- 
Switch 
Functional Programming may look 
scary for an object-oriented 
developer because of all the strange 
buzzwords like Functor, Referential 
Transparency, Monads, etc., but they 
are really just unfamiliar terms. 
Object-oriented programming can be 
a scary one with all its concepts, e.g. 
polymorphism, encapsulation, 
inheritance, covariance, etc. 
?@#?%!
FP OOP Key Concepts 
 Functional Programming is different in many ways from a 
standard imperative language, but there are a few major 
differences that are particularly important to understand: 
Function-oriented 
not 
object-oriented 
Expressions 
rather than 
Statements 
Immutable 
rather than 
mutable
What is "Functional 
Programming?" 
Functional programming is just a style, is a programming paradigm 
that treats computation as the evaluation of functions and avoids 
state and mutable data… 
 “Functions as primary building blocks” (first-class functions) 
 programming with “immutable” variables and assignments, no state 
 Programs work by returning values instead of modifying data
What is "Functional 
Programming?" 
Functional programming is so called because a program consists entirely of 
functions. 
First class 
Higher-Order 
Functions 
Immutability 
Declarative 
λ 
… is all about functions! Identifying an abstraction and building a function, 
use existing functions to build more complex abstractions, pass existing 
functions to other functions to build even more complex abstractions
Functional characteristics 
Higher Order Function & Pure Function 
Immutability 
Composition 
Curry & Partial Application
Higher-Order functions 
A higher-order function is a function that takes another function as a 
parameter, or a function that returns another function as a value, or a 
function which does both.
Pure Functions - Properties and 
Benefits 
 A function always gives the same output value for a given 
input value 
 I can then cache the result 
 A Pure Function has no side effects 
 Pure functions can be executed in parallel 
 The function does not rely on any external state 
 Increased readability and maintainability 
 Pure functions can more easily isolated 
 easier testing and debugging
Pure Functions - Properties and 
Benefits
Pure Functions - Properties and 
Benefits
Pure Functions - Properties and 
Benefits
Side Effects 
Side effects aren’t bad…
Unwanted Side Effects are Evil! 
Side effects aren’t bad… 
unwanted side effects are EVIL 
and the root of many bugs! 
One of the biggest advantages with functional 
programming is that the order of execution of “side 
effect free functions” is not important. 
… “side effect free functions” are 
easy to parallelize
Currying 
Curry is a technique in which a function is applied to its 
arguments one at a time, with each 
application returning a new function 
that accepts the next argument 
Higher-order function enable 
Partial Application and Currying
Partial Application 
Partial Application refers to the process of fixing a 
number of arguments to a function, producing 
another function of smaller arity 
With both currying and partial application, you supply argument values and return a 
function that’s invokable with the missing arguments. But currying a function returns 
the next function in the chain, whereas partial application binds argument values to 
values that you supply during the operation, producing a function with a smaller arity
Immutability 
 Immutability is very important characteristic of FP but mostly is about transformation of 
state… … Immutable data forces you to use a “transformational” approach 
 When you’re writing programs using 
immutable types, the only “thing a method 
can do is return a result, it can’t modify the 
state of any objects 
 Immutable data makes the code predictable 
is easier to work 
 Prevent Bugs 
 Concurrency is much simpler, as you don’t 
have to worry about using locks to avoid 
update conflicts 
 Automatic thread-safe, controlling mutable state in
Immutability 
Mutable values cannot be captured by 
closures!
Function Composition 
Function Composition - Building with composition. Composition is the 
'glue' that allows us build larger systems from smaller ones. This is the very 
heart of the functional style. Almost every line of code is a composable 
expression. Composition is used to build basic functions, and then functions 
that use those functions, and so on. 
Composition — in the form of passed parameters plus first-class functions
Using functions as building 
blocks 
 A well-known principle of good design is to create a set of basic 
operations and then combine these building blocks in various 
ways to build up more complex behaviors
Compose Mario 
Mario game sample, based on functional reactive Elm script (http://elm-lang. 
org/edit/examples/Intermediate/Mario.elm) 
The functions that depend on keyboard take the current keyboard state as the first argument. This is 
represented as a tuple int*int (dir) consisting of x and y directions. 
The step function of the game takes previous Mario value and returns a new one. It is composed from 4 
functions that represent different aspects of the game.
Why functional programming in C# & F#
Memoization 
Memoization enables automatic caching of recurring 
function-return values.
Lazy Evaluation - Strict & Non-Strict 
Evaluation 
 Lazy evaluation deferral of expression evaluation for as long 
as possible until absolutely needed 
 Languages can be categorized as strict (eagerly evaluating 
all expressions) or lazy (deferring evaluation) 
 Strict evaluation always fully evaluates 
function arguments before invoking the 
function 
 Lazy evaluation does not evaluate function 
arguments unless their values are required to 
evaluate the function call itself
Recursion is the new iteration 
 In functional programming “iteration” is ~usually~ accomplished via 
recursion 
 Recursive function invoke themselves, Tail recursion is optimized by 
compiler avoiding to maintain a stack ~stack over flow!
Recursion is the new iteration 
 In functional programming “iteration” is ~usually~ accomplished via 
recursion
Recursion
Tail Recursion
Why functional programming in C# & F#
Why Functional Programming?
Why Functional Programming? 
 Changes the way you think about programming and problem 
solving 
 Functional Programming promotes Composition and Modularity 
 Simple Code for Complex Problems 
 Declarative programming style 
 Concurrency, FP is easy to parallelize 
 Locking vs. immutable memory 
 Conciseness, less code (no null checking) 
 Correctness & Reduced bugs (immutability) 
 Rapid Prototyping
Concurrency 
Modern computers come with 
multiple processors, each 
equipped with multiple cores, but 
the single processor is slower 
than used to be! Moore’s law 
(http://en.wikipedia.org/wiki/Moore's_law) 
… to achieve great performances the 
application must be leveraging a 
Concurrent Model
Concurrency 
There is a problem… 
the free lunch is over 
 Programs are not doubling in speed every 
couple of years for free anymore 
We need to start writing code to take 
advantage of many cores
Concurrency… jams to avoid! 
Parallel, asynchronous, 
concurrent, and reactive 
programs bring many 
challenges because these 
programs are nearly always 
nondeterministic 
 This makes debugging/testing 
challenging 
 Deadlocking 
 Not easy to program
Concurrency 
 Imperative and traditional 
programming styles gives 
us bad headaches 
 It’s difficult to turn existing sequential 
code into parallel code 
 Using shared state and locks is 
difficult 
 different threads can change the same
Concurrency 
 Functional programming feels 
good: 
 Thanks to the immutability (and isolation), 
we avoid introducing race conditions and we 
can write lock-free code. 
 Using a declarative programming style 
we can introduce parallelism into 
existing code easily. We can replace a 
few primitives that specify how to 
combine commands with version that 
executes commands in parallel
Concurrent Model Programming 
An Agent is an independent computational 
entity which contains a queue, and receives 
IMMUTABILITY + 
ISOLATION + 
and processes messages 
DECLARATIVE PROGRAMMING = 
------------------------------------------------ 
It provides immutability and isolation 
BEST CONCURRENT MODEL 
PROGRAMMING 
(it enforces coarse-grained isolation through message-passing)
What does an Agent look like?
Agent Model 
What does a 
system of 
actors look 
like?
Pipeline Processing 
 Pipeline according to Wikipedia: 
 A pipeline is a set of data processing elements 
connected in series, so that the output of one element 
is the input of the next one. The elements of a pipeline 
are often executed in parallel or in time-sliced fashion; 
in that case, some amount of buffer storage is often 
inserted between elements
Agent Async-BoundedQueue
Agent Async-BoundedQueue
Pipeline Processing 
 Values processed in multiple steps 
 Worker takes value, processes 
it, and sends it 
 Worker is blocked when source 
is empty 
 Worker is blocked when target 
is full 
 Steps of the pipeline run in 
parallel
Why functional programming in C# & F#
When Functional 
Programming?
Functional Job Trend 
Functional languages are 
sprouting not just on the 
JVM where the two most 
interesting new languages 
are Scala and Clojure, but 
also on the .NET platform, 
where F# is a first-class 
citizen 
http://www.itjobswatch.co.uk
Wrap-Up 
 Use functions as building block and composition to solve complex 
problem with simple code 
 Immutability and Isolation are your best friends to write concurrent 
application 
 Concurrency and reliability are becoming more and more required, FP will help you! 
 Functional and imperative styles should NOT stand in opposition 
but… 
…they should COEXIST 
 Poly-paradigm programming is more powerful 
and effective than polyglot programming
Q & A ? 
The tools we use have a profound (and devious!) influence on our 
thinking habits, and, therefore, on our thinking abilities. 
-- Edsger Dijkstra
References 
 Why Functional Programming Matters (John Hughes) 
http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf 
 http://rosettacode.org
How to reach me 
github.com/DCFsharp 
meetup.com/DC-fsharp/ 
@DCFsharp 
rterrell@microsoft.com

More Related Content

PDF
F# and SignalR for a FastWeb
PDF
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
PPT
C#3.0 & Vb 9.0 New Features
PPTX
Functional programming
PDF
FregeDay: Design and Implementation of the language (Ingo Wechsung)
PPT
Introduction to Procedural Programming in C++
PDF
New c sharp3_features_(linq)_part_iv
PPTX
C++ ppt
F# and SignalR for a FastWeb
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
C#3.0 & Vb 9.0 New Features
Functional programming
FregeDay: Design and Implementation of the language (Ingo Wechsung)
Introduction to Procedural Programming in C++
New c sharp3_features_(linq)_part_iv
C++ ppt

What's hot (20)

PPTX
C programming interview questions
PPT
C++ to java
PDF
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
PDF
Functional JavaScript Fundamentals
PPT
Programming In C++
PPT
C++ OOP Implementation
PPTX
Pascal Programming Language
PDF
Functional Programming in Python
PDF
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
DOCX
C++ question and answers
PPTX
PPTX
Immutable data structures - A Primer
PPTX
Programming Paradigm & Languages
PPTX
C# 101: Intro to Programming with C#
PPT
Intro. to prog. c++
PPT
Basic structure of C++ program
PPTX
C++vs java
PPTX
Introduction to F# 3.0
PDF
Python Programming - I. Introduction
PDF
Preparing for Scala 3
C programming interview questions
C++ to java
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
Functional JavaScript Fundamentals
Programming In C++
C++ OOP Implementation
Pascal Programming Language
Functional Programming in Python
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
C++ question and answers
Immutable data structures - A Primer
Programming Paradigm & Languages
C# 101: Intro to Programming with C#
Intro. to prog. c++
Basic structure of C++ program
C++vs java
Introduction to F# 3.0
Python Programming - I. Introduction
Preparing for Scala 3
Ad

Viewers also liked (20)

PDF
Functional Programming in C# and F#
PDF
Presentaciones digitales. MPM
PPTX
Learning the city powerpointfrom am v3
PPT
Lesson Four - Seerah
PDF
The New European PV Legislation: Issues and Challenges
PPTX
Crime thriller, md, jd, jh hg
PPTX
toxic molds
PPTX
Tolan revfinal conf_2013
PPTX
عروض موقع سوق مصر
PPTX
Lesson 21 - Building up to Prophethood
PPT
Lesson five miracles
PPT
Tahneek lesson 7
PPTX
Just cavalli presentation
PPT
ConnectME: connecting content for future TV & video
PDF
Trecho de "O livro das religiões"
PPTX
Empirical Experiment on Navigation with Social Tags
PDF
Bringithomefurniture pdf
PDF
Connected Media Experiences
PPTX
Lesson 13 Death of Amina, In the care of Abdul Muttalib and Abu Talib.
Functional Programming in C# and F#
Presentaciones digitales. MPM
Learning the city powerpointfrom am v3
Lesson Four - Seerah
The New European PV Legislation: Issues and Challenges
Crime thriller, md, jd, jh hg
toxic molds
Tolan revfinal conf_2013
عروض موقع سوق مصر
Lesson 21 - Building up to Prophethood
Lesson five miracles
Tahneek lesson 7
Just cavalli presentation
ConnectME: connecting content for future TV & video
Trecho de "O livro das religiões"
Empirical Experiment on Navigation with Social Tags
Bringithomefurniture pdf
Connected Media Experiences
Lesson 13 Death of Amina, In the care of Abdul Muttalib and Abu Talib.
Ad

Similar to Why functional programming in C# & F# (20)

PDF
Introduction to functional programming
PPTX
Exploring the Real Power of Functional Programming
PDF
Introduction to functional programming
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
PPTX
Functional programming
PPTX
From Imperative to Functional Programming (for Absolute Beginners)
PDF
"Functional Programming in a Nutshell" by Adityo Pratomo (Froyo Framework)
PDF
Functional programming
PPTX
Functional Programming
PPTX
Introduction to Functional Programming
PPTX
Functional Paradigm.pptx
PDF
Introduction to Functional Programming
PPTX
Functional programming
PDF
Functional programming is the most extreme programming
PPTX
When life gives you functions make functional programs!
PDF
Functional programming
PDF
Functional programming in C++
PDF
Introduction to functional programming (In Arabic)
PDF
Intro to functional programming - Confoo
PPTX
Functional Programming Introduction
Introduction to functional programming
Exploring the Real Power of Functional Programming
Introduction to functional programming
Столпы функционального программирования для адептов ООП, Николай Мозговой
Functional programming
From Imperative to Functional Programming (for Absolute Beginners)
"Functional Programming in a Nutshell" by Adityo Pratomo (Froyo Framework)
Functional programming
Functional Programming
Introduction to Functional Programming
Functional Paradigm.pptx
Introduction to Functional Programming
Functional programming
Functional programming is the most extreme programming
When life gives you functions make functional programs!
Functional programming
Functional programming in C++
Introduction to functional programming (In Arabic)
Intro to functional programming - Confoo
Functional Programming Introduction

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
sap open course for s4hana steps from ECC to s4

Why functional programming in C# & F#

  • 1. OOP makes code understandable by encapsulating moving parts. FP makes code understandable by eliminating moving parts. Riccardo Terrell – Silicon Valley Code Camp 2014 — Michael Feathers (author of Working with Legacy Code)
  • 2. Agenda History and influence of Functional Programming Functional vs Imperative Programming What is Functional Programming Functional Programming characteristics Why Functional Programming
  • 3. History LISP ISWIM APL ML 1973 FP 1958 1966 1962 1977 2005F# Clojure 1988Haskell Scala 2003 2007 Ocam 1996 l 1930 -ish 1986Erlang λ
  • 4. Functional Programming Influence  Continue Evolution of GC – Lisp ~1958  Generics – ML ~ 1973  In early 1994, support for lambda, filter, map, and reduce was added to Python  List comprehension - Linq in C# 3.0 and Java 8  First-class functions were also introduce Visual Basic 9, C# and C++ 11  Java 8 supports lambda expressions as a replacement for anonymous classes  Is Lazy Evaluation is part of the main stream languages such as C#  Type Inference, example is the “var” keyword in C# Programming in a functional style can also be accomplished in languages that aren't
  • 5. Objectives  Use functions as building block and composition to solve complex problem with simple code  Immutability and Isolation are your best friends to write concurrent application  Concurrency and reliability are becoming more and more required, FP will help you!  Functional and imperative styles should NOT stand in opposition … … they should COEXIST  Poly-paradigm programming is more powerful and effective than polyglot programming
  • 6. FP vs OOP the Paradigm- Switch Functional Programming may look scary for an object-oriented developer because of all the strange buzzwords like Functor, Referential Transparency, Monads, etc., but they are really just unfamiliar terms. Object-oriented programming can be a scary one with all its concepts, e.g. polymorphism, encapsulation, inheritance, covariance, etc. ?@#?%!
  • 7. FP OOP Key Concepts  Functional Programming is different in many ways from a standard imperative language, but there are a few major differences that are particularly important to understand: Function-oriented not object-oriented Expressions rather than Statements Immutable rather than mutable
  • 8. What is "Functional Programming?" Functional programming is just a style, is a programming paradigm that treats computation as the evaluation of functions and avoids state and mutable data…  “Functions as primary building blocks” (first-class functions)  programming with “immutable” variables and assignments, no state  Programs work by returning values instead of modifying data
  • 9. What is "Functional Programming?" Functional programming is so called because a program consists entirely of functions. First class Higher-Order Functions Immutability Declarative λ … is all about functions! Identifying an abstraction and building a function, use existing functions to build more complex abstractions, pass existing functions to other functions to build even more complex abstractions
  • 10. Functional characteristics Higher Order Function & Pure Function Immutability Composition Curry & Partial Application
  • 11. Higher-Order functions A higher-order function is a function that takes another function as a parameter, or a function that returns another function as a value, or a function which does both.
  • 12. Pure Functions - Properties and Benefits  A function always gives the same output value for a given input value  I can then cache the result  A Pure Function has no side effects  Pure functions can be executed in parallel  The function does not rely on any external state  Increased readability and maintainability  Pure functions can more easily isolated  easier testing and debugging
  • 13. Pure Functions - Properties and Benefits
  • 14. Pure Functions - Properties and Benefits
  • 15. Pure Functions - Properties and Benefits
  • 16. Side Effects Side effects aren’t bad…
  • 17. Unwanted Side Effects are Evil! Side effects aren’t bad… unwanted side effects are EVIL and the root of many bugs! One of the biggest advantages with functional programming is that the order of execution of “side effect free functions” is not important. … “side effect free functions” are easy to parallelize
  • 18. Currying Curry is a technique in which a function is applied to its arguments one at a time, with each application returning a new function that accepts the next argument Higher-order function enable Partial Application and Currying
  • 19. Partial Application Partial Application refers to the process of fixing a number of arguments to a function, producing another function of smaller arity With both currying and partial application, you supply argument values and return a function that’s invokable with the missing arguments. But currying a function returns the next function in the chain, whereas partial application binds argument values to values that you supply during the operation, producing a function with a smaller arity
  • 20. Immutability  Immutability is very important characteristic of FP but mostly is about transformation of state… … Immutable data forces you to use a “transformational” approach  When you’re writing programs using immutable types, the only “thing a method can do is return a result, it can’t modify the state of any objects  Immutable data makes the code predictable is easier to work  Prevent Bugs  Concurrency is much simpler, as you don’t have to worry about using locks to avoid update conflicts  Automatic thread-safe, controlling mutable state in
  • 21. Immutability Mutable values cannot be captured by closures!
  • 22. Function Composition Function Composition - Building with composition. Composition is the 'glue' that allows us build larger systems from smaller ones. This is the very heart of the functional style. Almost every line of code is a composable expression. Composition is used to build basic functions, and then functions that use those functions, and so on. Composition — in the form of passed parameters plus first-class functions
  • 23. Using functions as building blocks  A well-known principle of good design is to create a set of basic operations and then combine these building blocks in various ways to build up more complex behaviors
  • 24. Compose Mario Mario game sample, based on functional reactive Elm script (http://elm-lang. org/edit/examples/Intermediate/Mario.elm) The functions that depend on keyboard take the current keyboard state as the first argument. This is represented as a tuple int*int (dir) consisting of x and y directions. The step function of the game takes previous Mario value and returns a new one. It is composed from 4 functions that represent different aspects of the game.
  • 26. Memoization Memoization enables automatic caching of recurring function-return values.
  • 27. Lazy Evaluation - Strict & Non-Strict Evaluation  Lazy evaluation deferral of expression evaluation for as long as possible until absolutely needed  Languages can be categorized as strict (eagerly evaluating all expressions) or lazy (deferring evaluation)  Strict evaluation always fully evaluates function arguments before invoking the function  Lazy evaluation does not evaluate function arguments unless their values are required to evaluate the function call itself
  • 28. Recursion is the new iteration  In functional programming “iteration” is ~usually~ accomplished via recursion  Recursive function invoke themselves, Tail recursion is optimized by compiler avoiding to maintain a stack ~stack over flow!
  • 29. Recursion is the new iteration  In functional programming “iteration” is ~usually~ accomplished via recursion
  • 34. Why Functional Programming?  Changes the way you think about programming and problem solving  Functional Programming promotes Composition and Modularity  Simple Code for Complex Problems  Declarative programming style  Concurrency, FP is easy to parallelize  Locking vs. immutable memory  Conciseness, less code (no null checking)  Correctness & Reduced bugs (immutability)  Rapid Prototyping
  • 35. Concurrency Modern computers come with multiple processors, each equipped with multiple cores, but the single processor is slower than used to be! Moore’s law (http://en.wikipedia.org/wiki/Moore's_law) … to achieve great performances the application must be leveraging a Concurrent Model
  • 36. Concurrency There is a problem… the free lunch is over  Programs are not doubling in speed every couple of years for free anymore We need to start writing code to take advantage of many cores
  • 37. Concurrency… jams to avoid! Parallel, asynchronous, concurrent, and reactive programs bring many challenges because these programs are nearly always nondeterministic  This makes debugging/testing challenging  Deadlocking  Not easy to program
  • 38. Concurrency  Imperative and traditional programming styles gives us bad headaches  It’s difficult to turn existing sequential code into parallel code  Using shared state and locks is difficult  different threads can change the same
  • 39. Concurrency  Functional programming feels good:  Thanks to the immutability (and isolation), we avoid introducing race conditions and we can write lock-free code.  Using a declarative programming style we can introduce parallelism into existing code easily. We can replace a few primitives that specify how to combine commands with version that executes commands in parallel
  • 40. Concurrent Model Programming An Agent is an independent computational entity which contains a queue, and receives IMMUTABILITY + ISOLATION + and processes messages DECLARATIVE PROGRAMMING = ------------------------------------------------ It provides immutability and isolation BEST CONCURRENT MODEL PROGRAMMING (it enforces coarse-grained isolation through message-passing)
  • 41. What does an Agent look like?
  • 42. Agent Model What does a system of actors look like?
  • 43. Pipeline Processing  Pipeline according to Wikipedia:  A pipeline is a set of data processing elements connected in series, so that the output of one element is the input of the next one. The elements of a pipeline are often executed in parallel or in time-sliced fashion; in that case, some amount of buffer storage is often inserted between elements
  • 46. Pipeline Processing  Values processed in multiple steps  Worker takes value, processes it, and sends it  Worker is blocked when source is empty  Worker is blocked when target is full  Steps of the pipeline run in parallel
  • 49. Functional Job Trend Functional languages are sprouting not just on the JVM where the two most interesting new languages are Scala and Clojure, but also on the .NET platform, where F# is a first-class citizen http://www.itjobswatch.co.uk
  • 50. Wrap-Up  Use functions as building block and composition to solve complex problem with simple code  Immutability and Isolation are your best friends to write concurrent application  Concurrency and reliability are becoming more and more required, FP will help you!  Functional and imperative styles should NOT stand in opposition but… …they should COEXIST  Poly-paradigm programming is more powerful and effective than polyglot programming
  • 51. Q & A ? The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities. -- Edsger Dijkstra
  • 52. References  Why Functional Programming Matters (John Hughes) http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf  http://rosettacode.org
  • 53. How to reach me github.com/DCFsharp meetup.com/DC-fsharp/ @DCFsharp rterrell@microsoft.com

Editor's Notes

  • #30: Recursion to do not modify the list
  • #34: Many people find functional programming elegant or even beautiful, but that’s hardly a good reason to use it in a commercial environment. Elegance doesn’t pay the bills, sad to say. One of the big reason for coding in a functional style is that it makes you and your team more productive.