SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

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