SlideShare une entreprise Scribd logo
1  sur  28
FUNCTIONAL
PROGRAMMING (FP)
Prateek Jain
(prateekjainaa@gmail.com)
Is OOPs, oops?
• NullPointer problems
• Inheritance issues
• “new” operator issues
Is OOPs, oops?
• NullPointer problems
• Inheritance issues
• “new” operator issues
Is OOPs, oops?
• NullPointer problems
• Inheritance issues
• “new” operator issues
Why FP?
• I Have to Be Good at Writing Concurrent Programs
• Most Programs Are Just Data Management Problems

(why ORM?)
• More Modular
• I Have to Work Faster and Faster
• Code is written once, but read many times
Why FP?
• I Have to Be Good at Writing Concurrent Programs
• Most Programs Are Just Data Management Problems

(why ORM?)
• More Modular
• I Have to Work Faster and Faster
• Code is written once, but read many times
Why FP?
• I Have to Be Good at Writing Concurrent Programs
• Most Programs Are Just Data Management Problems

(why ORM?)
• More Modular
• I Have to Work Faster and Faster
• Code is written once, but read many times
Why FP?
• I Have to Be Good at Writing Concurrent Programs
• Most Programs Are Just Data Management Problems

(why ORM?)
• More Modular
• I Have to Work Faster and Faster
• Code is written once, but read many times
Why FP?
• I Have to Be Good at Writing Concurrent Programs
• Most Programs Are Just Data Management Problems

(why ORM?)
• More Modular
• I Have to Work Faster and Faster
• Code is written once, but read many times
What is FP?
• RECURSION
• ABSTRACTION
• HIGHER ORDER FUNCTIONS
• IMPACT MOST PROGRAMMING LANGUAGES
PROGRAMS AS FUNCTIONS
• PROGRAM = DESCRIPTION OF A SPECIFIC

COMPUTATION
• Y = F(X)
• F: X ->Y

• MATHEMATICS
• VARIABLES = ACTUAL VALUES
• NO MEMEORY ALLOCATION CONCEPT
• IMPERATIVE LANGUAGE
• VARIABLES = MEMORY LOCATIONS + VALUES
PROGRAMS AS FUNCTIONS
• NO LOOPS BUT RECURSION
• NO VARIABLE EXCEPT AS A NAME FOR A VALUE
• NO ASSIGNMENT OPERATION (x = x+1 ,

MEANINGLESS)
• ONLY CONSTANTS, PARAMETERS AND VALUES
imperative

functional

EXAMPLE
Void GCD (int u, int v, int* x) {
Int y, t, z;
z = u;
y = v;
While (y!=0) {
…
…
}
…
}

Void GCD(int u, int v) {
if(v==0)
return u;
else
return GCD(v, u%v);
}
NO VARIABLES, NO ASSIGNMENT
• No notion of the internal state of a function.
• Referential Transparency.
• Value Semantics.
FP vs Others
• Recursions instead of loops
• Pattern matching instead of “if”
• Pattern matching instead of state machines
• Information transformation instead of sequence of tasks
FP vs Others
• Persistent data structures
• Powerful concurrency constructs : Actors
• Software transactional memory
• Avoid “Null”
What it really means?
• Immutability is good
What it really means?
• Immutability is good
• No bugs (due to nasty side effects)
What it really means?
• Immutability is good
• No bugs (due to nasty side effects)
• Benefits from concurrency
What it really means?
• Immutability is good
• No bugs (due to nasty side effects)
• Benefits from concurrency
• No more messy loops
What it really means?
• Immutability is good
• No bugs (due to nasty side effects)
• Benefits from concurrency
• No more messy loops
• Lazy evaluation
FP Examples
• Erlang, Haskell, Clojure
• F#
• JAVA 8 (prject lambda), Scala, Groovy
• R, Mathematica etc. (specialized languages)
CAUTION CAUTION
Maintaining, Maintainability
• Use functional style wheretill it makes the intent more

readable.
Sort(extract(filter(having(on(Pet.class).getSpecies(), is(Dog)), pets,
on(Pet.class).getName()), on(String.class));

List<Pet> dogs =
filter(having(on(Pet.class).getSpecies(), is(Dog)), pets);
List<String> dogNames = extract(dogs, on(Pet.class).getName());
List<String> sortedDogNames = sort(dogNames, on(String.class));
Maintaining, Maintainability

• One liners are always not better.

Convert(pets, new Convert<Pet, VetStay>() {
@override public VetStay converter(Pet pet) {
return new VetStay(pet, new Date(), “….”);
}});

Private Converter<Pet, VetStay> toVetStay () {
@override public VetStay converter(Pet pet) {
return new VetStay(pet, new Date(), “….”);
}});
Convert(pets, toVetStay());
FP - Adoption
• Facebook (tchat), Linkedin uses Erlang
• Twitter, UBS, Credit Suisse uses Scala
QUESTIONS?
Questions?
FEEDBACK
Feedback

Contenu connexe

En vedette

Interactive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using SparkInteractive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using Spark
Kevin Mader
 
Functional programming
Functional programmingFunctional programming
Functional programming
edusmildo
 
Machine Learning with Apache Mahout
Machine Learning with Apache MahoutMachine Learning with Apache Mahout
Machine Learning with Apache Mahout
Daniel Glauser
 

En vedette (11)

Interactive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using SparkInteractive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using Spark
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
 
The Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptThe Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScript
 
Machine Learning with Apache Mahout
Machine Learning with Apache MahoutMachine Learning with Apache Mahout
Machine Learning with Apache Mahout
 
Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Predictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive IndustryPredictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive Industry
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 

Similaire à Functional programming

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
Clay Helberg
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adam
Adam Essenmacher
 

Similaire à Functional programming (20)

Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
A (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingA (very brief) into to Functional Programming
A (very brief) into to Functional Programming
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)
 
Logic programming in python
Logic programming in pythonLogic programming in python
Logic programming in python
 
Oop is not Dead
Oop is not DeadOop is not Dead
Oop is not Dead
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
 
Craft of coding
Craft of codingCraft of coding
Craft of coding
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
 
Introduction to functional programming with JavaScript
Introduction to functional programming with JavaScriptIntroduction to functional programming with JavaScript
Introduction to functional programming with JavaScript
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)Become Jythonic in FDMEE (KSCOPE15)
Become Jythonic in FDMEE (KSCOPE15)
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
PARADIGM IT.pptx
PARADIGM IT.pptxPARADIGM IT.pptx
PARADIGM IT.pptx
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adam
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Functional programming

  • 2. Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues
  • 3. Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues
  • 4. Is OOPs, oops? • NullPointer problems • Inheritance issues • “new” operator issues
  • 5. Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • 6. Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • 7. Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • 8. Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • 9. Why FP? • I Have to Be Good at Writing Concurrent Programs • Most Programs Are Just Data Management Problems (why ORM?) • More Modular • I Have to Work Faster and Faster • Code is written once, but read many times
  • 10. What is FP? • RECURSION • ABSTRACTION • HIGHER ORDER FUNCTIONS • IMPACT MOST PROGRAMMING LANGUAGES
  • 11. PROGRAMS AS FUNCTIONS • PROGRAM = DESCRIPTION OF A SPECIFIC COMPUTATION • Y = F(X) • F: X ->Y • MATHEMATICS • VARIABLES = ACTUAL VALUES • NO MEMEORY ALLOCATION CONCEPT • IMPERATIVE LANGUAGE • VARIABLES = MEMORY LOCATIONS + VALUES
  • 12. PROGRAMS AS FUNCTIONS • NO LOOPS BUT RECURSION • NO VARIABLE EXCEPT AS A NAME FOR A VALUE • NO ASSIGNMENT OPERATION (x = x+1 , MEANINGLESS) • ONLY CONSTANTS, PARAMETERS AND VALUES
  • 13. imperative functional EXAMPLE Void GCD (int u, int v, int* x) { Int y, t, z; z = u; y = v; While (y!=0) { … … } … } Void GCD(int u, int v) { if(v==0) return u; else return GCD(v, u%v); }
  • 14. NO VARIABLES, NO ASSIGNMENT • No notion of the internal state of a function. • Referential Transparency. • Value Semantics.
  • 15. FP vs Others • Recursions instead of loops • Pattern matching instead of “if” • Pattern matching instead of state machines • Information transformation instead of sequence of tasks
  • 16. FP vs Others • Persistent data structures • Powerful concurrency constructs : Actors • Software transactional memory • Avoid “Null”
  • 17. What it really means? • Immutability is good
  • 18. What it really means? • Immutability is good • No bugs (due to nasty side effects)
  • 19. What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency
  • 20. What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency • No more messy loops
  • 21. What it really means? • Immutability is good • No bugs (due to nasty side effects) • Benefits from concurrency • No more messy loops • Lazy evaluation
  • 22. FP Examples • Erlang, Haskell, Clojure • F# • JAVA 8 (prject lambda), Scala, Groovy • R, Mathematica etc. (specialized languages)
  • 24. Maintaining, Maintainability • Use functional style wheretill it makes the intent more readable. Sort(extract(filter(having(on(Pet.class).getSpecies(), is(Dog)), pets, on(Pet.class).getName()), on(String.class)); List<Pet> dogs = filter(having(on(Pet.class).getSpecies(), is(Dog)), pets); List<String> dogNames = extract(dogs, on(Pet.class).getName()); List<String> sortedDogNames = sort(dogNames, on(String.class));
  • 25. Maintaining, Maintainability • One liners are always not better. Convert(pets, new Convert<Pet, VetStay>() { @override public VetStay converter(Pet pet) { return new VetStay(pet, new Date(), “….”); }}); Private Converter<Pet, VetStay> toVetStay () { @override public VetStay converter(Pet pet) { return new VetStay(pet, new Date(), “….”); }}); Convert(pets, toVetStay());
  • 26. FP - Adoption • Facebook (tchat), Linkedin uses Erlang • Twitter, UBS, Credit Suisse uses Scala