Functional Programming Paradigm: Courses
Functional Programming Paradigm: Courses
90% Refund @Courses Trending Now Data Structures & Algorithms Foundational Courses Data Science
Introduction
Functional programming is a programming paradigm in which we try to bind
everything in pure mathematical functions style. It is a declarative type of
programming style. Its main focus is on “what to solve” in contrast to an
imperative style where the main focus is “how to solve”. It uses expressions
instead of statements. An expression is evaluated to produce a value
whereas a statement is executed to assign variables. Those functions have
some special features discussed below.
Pure functions
Recursion
Referential transparency
Functions are First-Class and can be Higher-Order
https://www.geeksforgeeks.org/functional-programming-paradigm/ 1/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
Pure functions: These functions have two main properties. First, they
always produce the same output for same arguments irrespective of
anything else.
Secondly, they have no side-effects i.e. they do not modify any arguments or
local/global variables or input/output streams.
Later property is called immutability. The pure function’s only result is the
value it returns. They are deterministic.
Programs done using functional programming are easy to debug because
pure functions have no side effects or hidden I/O. Pure functions also make it
easier to write parallel/concurrent applications. When the code is written in
this style, a smart compiler can do many things – it can parallelize the
instructions, wait to evaluate results when needing them, and memorize the
results since the results never change as long as the input doesn’t change.
example of the pure function:
fib(n)
if (n <= 1)
return 1;
else
return fib(n - 1) + fib(n - 2);
https://www.geeksforgeeks.org/functional-programming-paradigm/ 2/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
variable can be replaced with its actual value at any point of execution. State
of any variable is constant at any instant.
Example:
Example:
can’t modify existing variables, and this really helps to maintain state
throughout the runtime of a program. Once we create a variable and set its
value, we can have full confidence knowing that the value of that variable
will never change.
Advantages:
1. Pure functions are easier to understand because they don’t change any
states and depend only on the input given to them. Whatever output they
produce is the return value they give. Their function signature gives all
the information about them i.e. their return type and their arguments.
2. The ability of functional programming languages to treat functions as
values and pass them to functions as parameters make the code more
readable and easily understandable.
3. Testing and debugging is easier. Since pure functions take only
arguments and produce output, they don’t produce any changes don’t
take input or produce some hidden output. They use immutable values, so
it becomes easier to check some problems in programs written uses pure
functions.
4. It is used to implement concurrency/parallelism because pure functions
don’t change variables or any other data outside of it.
5. It adopts lazy evaluation which avoids repeated evaluation because the
value is evaluated and stored only when it is needed.
Disadvantages:
Applications:
https://www.geeksforgeeks.org/functional-programming-paradigm/ 4/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
Fact: Whatsapp needs only 50 engineers for its 900M users because Erlang
is used to implement its concurrency needs. Facebook uses Haskell in its
anti-spam system.
Whether you're preparing for your first job interview or aiming to upskill in
this ever-evolving tech landscape, GeeksforGeeks Courses are your key to
success. We provide top-quality content at affordable prices, all geared
towards accelerating your growth in a time-bound manner. Join the millions
we've already empowered, and we're here to do the same for you. Don't
miss out - check it out now!
Looking for a place to share your ideas, learn, and connect? Our Community
portal is just the spot! Come join us and see what all the buzz is about!
Previous Next
Similar Reads
https://www.geeksforgeeks.org/functional-programming-paradigm/ 5/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
Complete Tutorials
GeeksforGeeks Online Tutorials - FREE! ChatGPT Tutorial: ChatGPT-3.5 Guide
for Beginners
V Vishalxviii
Additional Information
https://www.geeksforgeeks.org/functional-programming-paradigm/ 6/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Apply for Mentor Geeks Community
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets
https://www.geeksforgeeks.org/functional-programming-paradigm/ 7/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
Tutorials Archive
https://www.geeksforgeeks.org/functional-programming-paradigm/ 8/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
OOAD NodeJS
System Design Bootcamp Lodash
Interview Questions Web Browser
https://www.geeksforgeeks.org/functional-programming-paradigm/ 9/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks
https://www.geeksforgeeks.org/functional-programming-paradigm/ 10/10