SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 

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