0% found this document useful (0 votes)
33 views5 pages

TPL Lect 13-14

Uploaded by

shafiqfiverr345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

TPL Lect 13-14

Uploaded by

shafiqfiverr345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

.

Functional programming
Functional programming languages are specially designed to handle
symbolic computation and list-processing applications. Functional
programming is based on mathematical functions. Its main focus is
on “what to solve” in contrast to an imperative style where the main
focus is “how to solve”. Some of the popular functional programming
languages include Lisp, Erlang, Haskell, Clojure, etc.

Functional Programming is based on Lambda Calculus:

Lambda calculus is a framework developed by Alonzo Church to study


computations with functions. It can be called the smallest
programming language in the world. It defines what is computable.
Anything that can be computed by lambda calculus is computable. It
is equivalent to Turing machine in its ability to compute. It provides
a theoretical framework for describing functions and their evaluation.
It forms the basis of almost all current functional programming
languages.

Fact: Alan Turing was a student of Alonzo Church who created the
Turing machine which laid the foundation of the imperative
programming style

Functional programming languages are categorized into two groups,


i.e. −

 Pure Functional Languages − These types of functional languages


support only the functional paradigms. For example − Haskell.

 Impure Functional Languages − These types of functional


languages support the functional paradigms and imperative
style programming. For example − LISP.
Functional Programming – Characteristics
The most prominent characteristics of functional programming are
as follows −

 Functional programming languages are designed on the


concept of mathematical functions that use conditional
expressions and recursion to perform computation.
 Functional programming supports higher-order functions and lazy
evaluation features.
 Functional programming languages don’t support flow Controls
like loop statements and conditional statements like If-Else
and Switch Statements. They directly use the functions and
functional calls.
 Like OOP, functional programming languages support popular
concepts such as Abstraction, Encapsulation, Inheritance, and
Polymorphism.

Functional Programming – Advantages


Functional programming offers the following advantages −

 Bugs-Free Code − Functional programming does not


support state, so there are no side-effect results and we can
write error-free codes.
 Efficient Parallel Programming − Functional programming
languages have NO Mutable state, so there are no state-
change issues. One can program "Functions" to work parallel
as "instructions". Such codes support easy reusability and
testability.
 Efficiency − Functional programs consist of independent units
that can run concurrently. As a result, such programs are more
efficient.
 Supports Nested Functions − Functional programming supports
Nested Functions.
 Lazy Evaluation − Functional programming supports Lazy
Functional Constructs like Lazy Lists, Lazy Maps, etc.
functional programming requires a large memory space. As it does
not have a state, you need to create new objects every time to
perform actions.

Functional Programming is used in situations where we have to


perform lots of different operations on the same set of data.

 Lisp is used for artificial intelligence applications like Machine


learning, language processing, Modeling of speech and vision,
etc.
 Embedded Lisp interpreters add programmability to some
systems like Emacs.

Functional Programming vs. Object-oriented Programming


The following table highlights the major differences between
functional programming and object-oriented programming –

Functional Programming OOP

Uses Immutable data. Uses Mutable data.

Follows Declarative Programming Follows Imperative Programming


Model. Model.

Focus is on: “What you are doing” Focus is on “How you are doing”

Not suitable for Parallel


Supports Parallel Programming
Programming

Its methods can produce serious


Its functions have no-side effects
side effects.

Flow Control is done using function Flow control is done using loops and
calls & function calls with recursion conditional statements.

It uses "Loop" concept to iterate


It uses "Recursion" concept to
Collection Data. For example: For-
iterate Collection Data.
each loop in Java
The execution order of statements is Execution order of statements is
not so important. very important.

Supports both "Abstraction over


Supports only "Abstraction over
Data" and "Abstraction over
Data".
Behavior".

Efficiency of a Program Code


The efficiency of a programming code is directly proportional to the
algorithmic efficiency and the execution speed. Good efficiency
ensures higher performance.

The factors that affect the efficiency of a program includes −

 The speed of the machine


 Compiler speed
 Operating system
 Choosing right Programming language
 The way of data in a program is organized
 Algorithm used to solve the problem

The efficiency of a programming language can be improved by


performing the following tasks −

 By removing unnecessary code or the code that goes to


redundant processing.
 By making use of optimal memory and nonvolatile storage
 By making the use of reusable components wherever
applicable.
 By making use of error & and exception handling at all layers
of the program.
 By creating programming code that ensures data integrity and
consistency.
 By developing the program code that's compliant with the
design logic and flow.
An efficient programming code can reduce resource consumption
and completion time as much as possible with minimum risk to the
operating environment.

You might also like