SlideShare a Scribd company logo
1 of 17
Exploring the Real Power of
Functional Programming
Presented By:
Mahesh Chand (Software Consultant)
Divya Dua (Software Consultant)
Agenda
❏ Conclusion
❏ The Free Lunch Is Over
❏ The Downfall of Imperative Programming
❏ Rise of Functional Programming
❏ Imperative Style vs Declarative Style
❏ Pure Function
❏ Functional Composition
❏ Lazy Evaluation
The Free Lunch Is Over
Moore’s Law: The number of transistors are getting double in every 18 months.
Why don’t we have 10GHz Processor today ?
Chip designers are under so much pressure to deliver ever-faster CPUs that they’ll
risk changing the meaning of your program, and possibly break it, in order to make
it run faster.
What is free lunch actually ?
Programmers have not really had to worry much about performance or concurrency
because of moore’s law.
Application Developers did not need to invest in performance tuning and enjoyed
the free lunch from hardware improvement.
The Downfall of Imperative Programming
The nature of imperative coding is assignment programming.
Assignment programming leads to side effects.
When a function has side effect, you need another method to undo the side effect
For example, Opening a file to read, to undo the side effect, there is need to write
close method etc
An application which is working fine on single core processor but the moment it
runs on multicore system it starts behaving weird and ends up being broken.
Another problem arises from having mutable states. It is extremely difficult to work
with mutability especially when multiple threads start sharing it.
So, what’s the solution ?
Functional Programming
Rise of Functional Programming
Functional programming is an assignment less programming.
It is an inherently thread-safe. Silver bullet for leverage the multi-core processors.
It is like writing unix pipelines i.e a unix pipeline starts with a source of data — the
who command — and then transforms that data with one or more func-
tions. Data flows through the pipeline in only one direction, from one
function to the next, and data is never modified, it’s only transformed from
one format to another.
Imperative vs Declarative
● Hard to maintain and compose ● Easy to maintain and compose
● Need to tell what and how to do. ● Need to tell only what to do.
● Code is too verbose. ● Code is concise, not terse..
● Favours mutability. ● No explicit mutation.
● Sometimes, hard to
reason
● Easier to reason.
● Exhibit primitive
obsession.
● Highly expressive.
Pure Function
Pure function produces the same output no matter how many time you make a call
to it as long as you provide the same set of inputs.
Advantages of Pure functions:
● Easier to test
● Memoizable
● Referential transparency
● Easy to compose
● Easy to understand
Functional Composition
❏ One of the key features of Functional Programming.
❏ It is an act or mechanism to combine simple functions to build more
complicated ones.
❏ The result of each function is passed as the argument of the next function, and
the result of last one is the result of the whole.
❏ Functional Composition makes the code highly expressive, highly cohesive,
concise and easier to understand.
● Ordering using andThen: f(x) andThen g(x) = g(f(x))
● Ordering using compose: f(x) compose g(x) = f(g(x))
❏ You can make use of in-built functions andThen and compose to
combine multiple functions.
❏ Functional composition, as concept, refers to how we can compose
functions to form a pipeline of operations.
Lazy Evaluation
❏ Functional Composition makes code more expressive and lazy evaluation
adds efficiency to it.
❏ If the value is never needed during the execution of the program, the evaluation
of the expression can be totally skipped.
❏ Efficiency is achieved not just by running things faster, but by avoiding things
that shouldn't be done in the first place.
❏ When used in the context of functional programming, the word lazy may be
pronounced as efficient.
Conclusion
❖ Functional Programming is like an old wine in new bottle. It is healthy and
effective for multithreaded applications.
❖ Functional Programming is not a better model because it makes concurrency
easier; It makes concurrency easier because it is a better model.
❖ Using it, we can write code which is concise, highly expressive, uses no
garbage variables and has no explicit mutation.
❖ Object Oriented Programming makes the code understandable by
encapsulating moving parts while functional programming makes the code
understandable by minimizing the moving parts.
References
● The Free Lunch Is Over
● Robert C Martin - Functional Programming; What? Why? When?
● Functional Programming Basics
● Benefits of Pure Funcitons
● Lazy Evaluation
● Github URL - functional-programming
Exploring the Real Power of Functional Programming

More Related Content

Similar to Exploring the Real Power of Functional Programming

C Course material
C Course materialC Course material
C Course material
Fareed Khan
 

Similar to Exploring the Real Power of Functional Programming (20)

PROGRAMMING LANGUAGE AND TYPES
PROGRAMMING LANGUAGE AND TYPESPROGRAMMING LANGUAGE AND TYPES
PROGRAMMING LANGUAGE AND TYPES
 
Understanding concurrency
Understanding concurrencyUnderstanding concurrency
Understanding concurrency
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek parihar
 
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsEffects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAs
 
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
Effects, coeffects & subscriptions: a pit of success for SPAs Socracan18
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.
 
PCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptxPCCF UNIT 2 CLASS.pptx
PCCF UNIT 2 CLASS.pptx
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
Answers
AnswersAnswers
Answers
 
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
Laptop Devops: Putting Modern Infrastructure Automation to Work For Local Dev...
 
05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf05 Lecture - PARALLEL Programming in C ++.pdf
05 Lecture - PARALLEL Programming in C ++.pdf
 
C Course material
C Course materialC Course material
C Course material
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancoding
 
On component interface
On component interfaceOn component interface
On component interface
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
 
Learning to code in 2020
Learning to code in 2020Learning to code in 2020
Learning to code in 2020
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 

More from Knoldus Inc.

More from Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Exploring the Real Power of Functional Programming

  • 1. Exploring the Real Power of Functional Programming Presented By: Mahesh Chand (Software Consultant) Divya Dua (Software Consultant)
  • 2. Agenda ❏ Conclusion ❏ The Free Lunch Is Over ❏ The Downfall of Imperative Programming ❏ Rise of Functional Programming ❏ Imperative Style vs Declarative Style ❏ Pure Function ❏ Functional Composition ❏ Lazy Evaluation
  • 3. The Free Lunch Is Over Moore’s Law: The number of transistors are getting double in every 18 months. Why don’t we have 10GHz Processor today ? Chip designers are under so much pressure to deliver ever-faster CPUs that they’ll risk changing the meaning of your program, and possibly break it, in order to make it run faster. What is free lunch actually ? Programmers have not really had to worry much about performance or concurrency because of moore’s law. Application Developers did not need to invest in performance tuning and enjoyed the free lunch from hardware improvement.
  • 4.
  • 5. The Downfall of Imperative Programming The nature of imperative coding is assignment programming. Assignment programming leads to side effects. When a function has side effect, you need another method to undo the side effect For example, Opening a file to read, to undo the side effect, there is need to write close method etc An application which is working fine on single core processor but the moment it runs on multicore system it starts behaving weird and ends up being broken. Another problem arises from having mutable states. It is extremely difficult to work with mutability especially when multiple threads start sharing it. So, what’s the solution ?
  • 6.
  • 8. Rise of Functional Programming Functional programming is an assignment less programming. It is an inherently thread-safe. Silver bullet for leverage the multi-core processors. It is like writing unix pipelines i.e a unix pipeline starts with a source of data — the who command — and then transforms that data with one or more func- tions. Data flows through the pipeline in only one direction, from one function to the next, and data is never modified, it’s only transformed from one format to another.
  • 9. Imperative vs Declarative ● Hard to maintain and compose ● Easy to maintain and compose ● Need to tell what and how to do. ● Need to tell only what to do. ● Code is too verbose. ● Code is concise, not terse.. ● Favours mutability. ● No explicit mutation. ● Sometimes, hard to reason ● Easier to reason. ● Exhibit primitive obsession. ● Highly expressive.
  • 10. Pure Function Pure function produces the same output no matter how many time you make a call to it as long as you provide the same set of inputs. Advantages of Pure functions: ● Easier to test ● Memoizable ● Referential transparency ● Easy to compose ● Easy to understand
  • 11. Functional Composition ❏ One of the key features of Functional Programming. ❏ It is an act or mechanism to combine simple functions to build more complicated ones. ❏ The result of each function is passed as the argument of the next function, and the result of last one is the result of the whole.
  • 12. ❏ Functional Composition makes the code highly expressive, highly cohesive, concise and easier to understand. ● Ordering using andThen: f(x) andThen g(x) = g(f(x)) ● Ordering using compose: f(x) compose g(x) = f(g(x)) ❏ You can make use of in-built functions andThen and compose to combine multiple functions. ❏ Functional composition, as concept, refers to how we can compose functions to form a pipeline of operations.
  • 14. ❏ Functional Composition makes code more expressive and lazy evaluation adds efficiency to it. ❏ If the value is never needed during the execution of the program, the evaluation of the expression can be totally skipped. ❏ Efficiency is achieved not just by running things faster, but by avoiding things that shouldn't be done in the first place. ❏ When used in the context of functional programming, the word lazy may be pronounced as efficient.
  • 15. Conclusion ❖ Functional Programming is like an old wine in new bottle. It is healthy and effective for multithreaded applications. ❖ Functional Programming is not a better model because it makes concurrency easier; It makes concurrency easier because it is a better model. ❖ Using it, we can write code which is concise, highly expressive, uses no garbage variables and has no explicit mutation. ❖ Object Oriented Programming makes the code understandable by encapsulating moving parts while functional programming makes the code understandable by minimizing the moving parts.
  • 16. References ● The Free Lunch Is Over ● Robert C Martin - Functional Programming; What? Why? When? ● Functional Programming Basics ● Benefits of Pure Funcitons ● Lazy Evaluation ● Github URL - functional-programming