SlideShare a Scribd company logo
1 of 19
ThoughtWorks
Functional Programming
Coz it looks cool on a Resume
ThoughtWorks
The Curse of Functional Programming
Once you understand it,
you lose the ability to explain it to others.
ThoughtWorks
Where is it used?
• ThoughtWorks (Scala, Clojure)
• LinkedIn (Scala)
• Twitter (Scala)
• Facebook (Haskell, Clojure)
• SoundCloud (Scala)
• Akamai (Clojure)
AND MANY MORE
ThoughtWorks
Domain Co-Domain
-1
0
1
2
1
0
4
y = f(x)  Mathematical function
y = x^2  Square each element of domain
Function f(x) maps an Int to Int using square operation
ThoughtWorks
Jargon
Pure functions
Immutability
Higher Order Functions
Category Theory
Type StrictnessCurrying
Recursion
No Side Effects
Lambda Calculus
AND MANY MORE…
ThoughtWorks
Functional Programming
Programming with functions as building blocks
Programming with pure functions as building blocks
ThoughtWorks
Definition/Origins
• Based on Lamdba calculus invented in 1930s by Alonzo Church.
It states that a mathematical operation consists purely of functions.
• It’s also a style of programming that follows certain conventions, like some
of the jargon we saw earlier, viz. Immutability, Type strictness etc.
• Functional programming is programming without assignment statements
(Uncle Bob)
• An Expression based programming paradigm, viz. Using Expressions as
opposed to Statements, and combining expressions to form functions and
combining functions to form complex behaviours.
ThoughtWorks
Courtesy: Scott WlaschinThoughtWorks
Pure Functions
• For a valid input there’s one and only one valid output.
• Doesn’t modify variables out of its scope.
• In general, functions that have no side effects are pure functions.
• Advantages
a.Consistent reproducible results independent of the environment
b.Easier parallelization
c.Memoization or caching
d.Laziness
e.REFERENTIAL TRANSPARENCY
e.g.
f(x) = Math.sqrt(x)
i.e. -1 and Math.sin(90) is substitutable by 1, aka Referentially transparent
ThoughtWorks
Types
• Types are not classes!!
• Grouping of related values under a name.
• E.g. Int type groups all the mathematical Integers. Boolean groups
True and False.
• Provide compile time checks for correctness of the program.
• E.g. If you say 5 + Dog, Compiler will be upset.
ThoughtWorks
Recursion
• Because Loops have mutable nature and hence have side effects
• Recursion helps traverse tree structures more intuitively, e.g. listing
files
• Recursion is usually more concise
• Recursion not suited for all situations and uses more memory.
Scoped mutable state works just fine.
ThoughtWorks
First class citizens/Higher Order Functions
• Functions are first class like data, viz. literals and objects
• Functions can take other functions as arguments
• Functions can return a function as result
• Main advantage is partial application of function
ThoughtWorks
Currying with HOF
• A technique of transforming a multi-argument function in such a way
that it can be called as a chain of functions, each with a single/sub-set
of argument(s).
• Named after ....
• Better explained through examples
• Show me (pseudo)code!!
Haskell Curry
ThoughtWorks
Examples
ThoughtWorks
Advantages
• Easier reasoning while programming – More predictable
• Less cognitive overload – Less to keep in mind – Code Brevity
• Smaller solution space
• Easier debugging
• Cleaner/more readable code
• Saner Parallelization/Concurrency
• Better Modularization/Reuse
• Sharing data due to immutability
• Mapping, filtering, reducing, folding >>> cooler than looping
AND MANY MOREThoughtWorks
Limitations
• Real-world useful programs will have side effects.
• High barrier to entry
• it is very difficult to predict the nature of lazy programs(From
StackOverflow)
• Lack of good tools for debugging – Perhaps due to the nature of it
• Many a times FP is CPU/Memory intensive
• Unsuitable for low level – hardware bound programming and
scripting
• Functional fanatics are snobby
FEW MOREThoughtWorks
Questions
ThoughtWorks
Thank You
Siddharth Kulkarni
@sid_thinketh
ThoughtWorks

More Related Content

Viewers also liked

Viewers also liked (10)

Chat bots
Chat botsChat bots
Chat bots
 
Internet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & InovaçãoInternet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & Inovação
 
Agile Estimation And Planning
Agile Estimation And PlanningAgile Estimation And Planning
Agile Estimation And Planning
 
ThoughtWorks Digital - Estratégia de Dados
ThoughtWorks Digital - Estratégia de DadosThoughtWorks Digital - Estratégia de Dados
ThoughtWorks Digital - Estratégia de Dados
 
Data Strategy - Enabling the Data-Guided Enterprise
Data Strategy - Enabling the Data-Guided EnterpriseData Strategy - Enabling the Data-Guided Enterprise
Data Strategy - Enabling the Data-Guided Enterprise
 
ThoughtWorks Retail and Onefinestay - Business Model Innovation - Retail Week...
ThoughtWorks Retail and Onefinestay - Business Model Innovation - Retail Week...ThoughtWorks Retail and Onefinestay - Business Model Innovation - Retail Week...
ThoughtWorks Retail and Onefinestay - Business Model Innovation - Retail Week...
 
Olhares Diversos, Oportunidades Iguais | ThoughtWorks na HSM
Olhares Diversos, Oportunidades Iguais | ThoughtWorks na HSMOlhares Diversos, Oportunidades Iguais | ThoughtWorks na HSM
Olhares Diversos, Oportunidades Iguais | ThoughtWorks na HSM
 
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDASchulung: Einführung in das GPU-Computing mit NVIDIA CUDA
Schulung: Einführung in das GPU-Computing mit NVIDIA CUDA
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Basics of functional Programming by Siddharth Kulkarni

Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
Scala Italy
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
Gary Short
 

Similar to Basics of functional Programming by Siddharth Kulkarni (20)

10-DesignPatterns.ppt
10-DesignPatterns.ppt10-DesignPatterns.ppt
10-DesignPatterns.ppt
 
PARADIGM IT.pptx
PARADIGM IT.pptxPARADIGM IT.pptx
PARADIGM IT.pptx
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
Data Engineering with Solr and Spark
Data Engineering with Solr and SparkData Engineering with Solr and Spark
Data Engineering with Solr and Spark
 
Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
 
Introduction to Functional Programming and Clojure
Introduction to Functional Programming and ClojureIntroduction to Functional Programming and Clojure
Introduction to Functional Programming and Clojure
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Fun with flexible indexing
Fun with flexible indexingFun with flexible indexing
Fun with flexible indexing
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Doing data science with Clojure
Doing data science with ClojureDoing data science with Clojure
Doing data science with Clojure
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
PyCon HK 2018 - Heterogeneous job processing with Apache Kafka
 

Recently uploaded

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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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...
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 

Basics of functional Programming by Siddharth Kulkarni

  • 2. Functional Programming Coz it looks cool on a Resume ThoughtWorks
  • 3. The Curse of Functional Programming Once you understand it, you lose the ability to explain it to others. ThoughtWorks
  • 4. Where is it used? • ThoughtWorks (Scala, Clojure) • LinkedIn (Scala) • Twitter (Scala) • Facebook (Haskell, Clojure) • SoundCloud (Scala) • Akamai (Clojure) AND MANY MORE ThoughtWorks
  • 5. Domain Co-Domain -1 0 1 2 1 0 4 y = f(x)  Mathematical function y = x^2  Square each element of domain Function f(x) maps an Int to Int using square operation ThoughtWorks
  • 6. Jargon Pure functions Immutability Higher Order Functions Category Theory Type StrictnessCurrying Recursion No Side Effects Lambda Calculus AND MANY MORE… ThoughtWorks
  • 7. Functional Programming Programming with functions as building blocks Programming with pure functions as building blocks ThoughtWorks
  • 8. Definition/Origins • Based on Lamdba calculus invented in 1930s by Alonzo Church. It states that a mathematical operation consists purely of functions. • It’s also a style of programming that follows certain conventions, like some of the jargon we saw earlier, viz. Immutability, Type strictness etc. • Functional programming is programming without assignment statements (Uncle Bob) • An Expression based programming paradigm, viz. Using Expressions as opposed to Statements, and combining expressions to form functions and combining functions to form complex behaviours. ThoughtWorks
  • 10. Pure Functions • For a valid input there’s one and only one valid output. • Doesn’t modify variables out of its scope. • In general, functions that have no side effects are pure functions. • Advantages a.Consistent reproducible results independent of the environment b.Easier parallelization c.Memoization or caching d.Laziness e.REFERENTIAL TRANSPARENCY e.g. f(x) = Math.sqrt(x) i.e. -1 and Math.sin(90) is substitutable by 1, aka Referentially transparent ThoughtWorks
  • 11. Types • Types are not classes!! • Grouping of related values under a name. • E.g. Int type groups all the mathematical Integers. Boolean groups True and False. • Provide compile time checks for correctness of the program. • E.g. If you say 5 + Dog, Compiler will be upset. ThoughtWorks
  • 12. Recursion • Because Loops have mutable nature and hence have side effects • Recursion helps traverse tree structures more intuitively, e.g. listing files • Recursion is usually more concise • Recursion not suited for all situations and uses more memory. Scoped mutable state works just fine. ThoughtWorks
  • 13. First class citizens/Higher Order Functions • Functions are first class like data, viz. literals and objects • Functions can take other functions as arguments • Functions can return a function as result • Main advantage is partial application of function ThoughtWorks
  • 14. Currying with HOF • A technique of transforming a multi-argument function in such a way that it can be called as a chain of functions, each with a single/sub-set of argument(s). • Named after .... • Better explained through examples • Show me (pseudo)code!! Haskell Curry ThoughtWorks
  • 16. Advantages • Easier reasoning while programming – More predictable • Less cognitive overload – Less to keep in mind – Code Brevity • Smaller solution space • Easier debugging • Cleaner/more readable code • Saner Parallelization/Concurrency • Better Modularization/Reuse • Sharing data due to immutability • Mapping, filtering, reducing, folding >>> cooler than looping AND MANY MOREThoughtWorks
  • 17. Limitations • Real-world useful programs will have side effects. • High barrier to entry • it is very difficult to predict the nature of lazy programs(From StackOverflow) • Lack of good tools for debugging – Perhaps due to the nature of it • Many a times FP is CPU/Memory intensive • Unsuitable for low level – hardware bound programming and scripting • Functional fanatics are snobby FEW MOREThoughtWorks