hello everyone welcome to this session on functional versus object oriented
programming languages today in this session we will be telling
you the differences and the things in common between these two kind of
programming languages now when you talk about functional
programming languages uh examples of the c native language these do not
have the concepts like classes abstraction encapsulation etc and as you
might know these are basically object oriented concepts
now there are key differences between these programming languages and you
should know when to use which programming language and that is
exactly what we are going to cover in this session
so let's go ahead and start off with the session guys but before we start off
if you haven't already please subscribe to the intellipaat channel and also
click on that bell icon to never miss out on any updates from us
so now let's get started with the session
let's begin this quick comparison by understanding what functional
programming actually is well as the name suggests functional
program is basically a methodology that actually
involves in understanding what the result is rather than how we get to the
result for example the entire goal of a great
get product function or a get sum or a get difference function is to
know that you will always get the products
the sum and the difference whenever you give any inputs
to the function right for example if you're checking out the get product as
you can see on your screen right now this can always calculate the product of
two inputs and it'll give you the same input right so if we give
2 and 2 as the input we get 4 because 2 multiplied with 2 is 4
and if we give 3 multiplied with 6 we get 18
always so this you know this nature this property of
always having to provide the outputs knowing that you will get the expected
output and understanding not how you get there
but why and what is the outputs for the particular inputs
is all that functional programming mainly concentrates about
now with object oriented programming it's a little bit different because here
what we're trying to do is we're trying to understand
how the aspect of how rather than what to understand that we need to check out
the basis of object oriented programming and as the name suggests
when we talk about oop as it's called in short every single
entity every single thing that we deal in this programming paradigm is
basically an object so each of these objects will
have something called as attributes it will have some sort of
functionalities that will basically give you a description of what the
object is and what it does now let's consider a simple example of a
car right let's take a let's take any car as
an example so now the attributes basically describe
what the car is now think of it this way the car is of red color so that becomes
an attribute it has four doors it becomes a sedan if it had two
doors it was the coupe now it's a sports car as well so it goes
pretty fast it has shiny wheels and you know all of these describe the
car as in right you pretty much get the picture
now what can the car do this is what the functions will talk about
the car can go forward go back go sideways it can go really fast it can in
fact move and stop it has windscreen wipers it has air
conditioning and all of this so all of these are functions which will
basically describe the capabilities of the car
so this is like the basic example of how an object is handled in this paradigm
you know with the attributes and with the functionality as well
now with this quick understanding of both of these paradigms let us quickly
check out a comparison between functional and object oriented
programming structures now the first point i want to discuss is
definition so with definition as we've previously
checked out functional programming has to do
everything with just the evaluation part of it without having any
headache to understand how things work or you know without having to
give your time and effort into processing the how part of it
now with oop it's basically similar but here
everything is objectified every single thing that the programmer
you know tends to use tends to define tends to architect
is an object or it's considered as an object and hence the architecture
is called as object-oriented programming with point number two
uh you know it's a programming model because here is where the main
uh difference lies as we have been discussing for a minute or two now
because with functional programming you know it follows what we call as the
declarative programming model while oop follow something called as
imperative programming model so with functional programming what
we're trying to understand is basically the expressiveness of the logic without
having to describe how it works so hence the what
in the bracket now to give you a very quick example for you guys to understand
what declarative is and what imperative programming means
uh think of it like you want to build your dream house right
so you want to build a house so if you were to use declarative programming this
is how it would sound like i want a house and i want it by the
beach side i want a big kitchen and i want the house to be comfortable
this is how you would do it if it was functional programming
if it was imperative programming you would describe every single step you
would say hey let's go to the city of your choice
let's buy a plot of land let us build the basic
foundation structure of the house then you know eventually raise up all the
walls get the moulding done you know eventually do the interior as
per your requirement have a swimming pool make the house look beautiful and
all of these so you see the step-by-step architecture
right you concerned with the how rather than what so with declarative
programming you just said i want a big kitchen but then you never described you
know what you want exactly in that kitchen this this is where the
main difference lies between functional and oop
and of coming to the next point it's the support for parallel programming
here is where functional programming has a slight edge over
object oriented programming because with functional uh you know it does support
the parallel programming paradigm and it supports making use of distributed
computing for high efficiency usages with oop unfortunately it does not
support parallel programming as a whole but of course
there is a way through which you know you can try to imitate
parallel programming and immediate distributed computing through oop
but then on the whole it is not as efficient
as functional programming and neither does it function in a productive
environment as well so functional programming wins this round
coming to the next point it's data handling when we talk about data
handling there's a variety of data that you know we'll be using uh beat in
functional programming or object oriented programming
functional programming deals very well with immutable data that is the data
which you know does not change in real time where functioning is
set operations are set and in fact the operators are used to
perform operations in oop that's not the case oop is well known it
can handle mutable data where data is continuously changing and you know you
can basically have these objects have parameters have
functions which can know that there is the data being
changed and you know eventually understand
uh what's going on and work well as well so the basic definition here is if your
data doesn't change you would prefer functional programming
if your data changes a lot you know you would prefer object
oriented programming on the whole coming to point number five it's order
of execution with order of execution again here's a
major difference in functional programming your
statements can run in any order of choice
based on what the compiler is doing for example if there is a statement at line
number three which will direct the program to line number ten
and back to four back to five line number six line number eight whatever
order it is it can execute happily and will still
work object oriented programming is a bit stingy when it comes to that because
at the end of the day with object-oriented programming it
has to have an order there has to be a particular order
in execution because at the end of the day the architecture is based on that
again think of the car example a car is a very complex object right so to move
the car first you'll have to start it you cannot expect the car to start
moving on its own or uh you know basically you cannot turn on
the car without putting in the key and all of that right so if car is an
object certain minute things have to be followed in an ordered way to make sure
that everything works oops just like that now which one's
better is again very debatable but at this
point of time if you're learning if you're here watching this
video i would suggest that functional programming
will be a little flexible in terms of workability for you guys
now with that we can check out point number six point number six has to deal
with usage you know with usage as we've
already talked about in functional programming
if there are a lot of operations required but then there's
inputs which do not change uh inputs which are
you know similar and you already know the outputs or
you know what outputs sort of what you can expect
then functional programming is the way to go object-oriented programming is
preferred only when you know there are multiple inputs that
you want to process and there's a plethora of inputs but the
operations that you have to perform on it is
less then oop is preferred so to repeat my point functional programming is
preferred when there's more operations less operators with oop it's the exact
opposite it's few operations but more operators right
probably just take a second pause the screen and do take a note of
this point at the same time as well now coming to the next point it is core
components see with core components functional
programming and oop at the end of the day
are multi-paradigm supported they both give you a lot of features a lot of
components to work with with functional programming you will be
using functions and you will be using variables as the
inputs to these functions to you know have the whole operation together with
oop you have objects objects have certain
definition and after defining an object you'll have
the methods which will define what the object does
you will have attributes which will describe the object
and much more as well so in terms of simple usage
simple implementation i think functional programming will win this round as well
but in terms of detailed usage and in terms of how well you can define
something how well you can split it into the oop
structure and how well you can understand the workflow in detail and in
depth then oop uh takes a win as well so it
depends on what your use case is if it's simple go for functional programming if
it's complex and you want that complexity there
uh oop is the way to go now next thing is
ease of implementation which one's easy to implement
at the end of the day because functional programming can sometimes be
difficult because you know you have to think from a functional standpoint you
have to look at it from another perspective
to see what your inputs are doing how your inputs can be translated into a
workable output with oop that's not the case it's pretty
simple because you know it it depends on just taking
values and mapping it in real time and basically comparing it to your
uh real life functions as well right i just gave you a car example
and that is a perfect example for how an oop structure will work
and since with oop you can you know compare it and contrast it with anything
real life it makes it very easy to understand and it makes it very easy to
pretty much grasp if you're a beginner or an intermediate user as well so if
it's ease of implementation oop uh wins in my opinion
now which one's easier to learn because point number nine is all about that
in terms of ease of learning uh functional programming is pretty easy to
learn because of the only fact that it does not have
a complex data handling methodologies or any in-depth manipulation with respect
to the data like how we have in oops with oops that's not the case
oops is a bit complex if you're starting out because there's so many things you
have to look at there's so many attributes so many parameters
function definitions function calls method handling protocols
inheritance and many other complex which might
uh you know be a little overwhelming if you're beginning with
so with this uh you know you might have a question asking so
overall if you had to pick one which is better
well that's very difficult to say because you know functional programming
is amazingly powerful it's amazingly efficient when you have to do
new operations but you already have the input so you already have existing items
and there is no beating functional programming when it comes to this
and with the object oriented approach it's pretty much again based on
requirement if you have a requirement that says
you know i want all of my data to be extremely secure very tight knit very
packaged uh and i have to avoid unwanted access
unwanted usage it's amazing to go with the object-oriented
approach because every single entity is an object every single object will
have certain permissions uh that is required to access the object
so it makes it more secure and it's almost like taking a block of
legos and putting it uh and sorting it out in a box so that's
how the object-oriented approach is even though it might be a bit messy to
get started with but at the end of the day it's
worth the effort because it's that much more packaged and that much more secured
so what do you think about this comparison between functional
programming and object-oriented programming
so if you feel that if there's any more points that you think we should add to
this video again head to the comment section and do let us know
with that note you have come to the end of this comparison