Sei sulla pagina 1di 10

Functional Programming Object-Oriented Programming Programming Languages Related Questions

Computer Programming
Object-Oriented Programming: What is the

What is object oriented programming and difference between a function and a method?

functional programming? What is the difference What is the difference between object oriented
programming and non object oriented
between them? programming?

6 Answers What is the difference between object-oriented


and procedure-oriented programming?
Paul Pacheco, works at American Airlines
What is functional programming and oriented
Answered Apr 5 · Author has 950 answers and 2.3m answer views
functional programming?
Originally Answered: What is the difference between functional programming and object-oriented
programming? What's the difference between Object Oriented
You can write applications using either object-oriented programming or Programming and Procedural Programming?

functional programming. You can even use both at the same time. The What is the difference between structured
programming and object-oriented programming?
difference is how they organize the code and data, 2 different ways of thinking
and solving problems. What are the advantages of functional
programming over object-oriented programming?
Object oriented programming What are some languages that are mainly
functional?

As the name implies, you break down your program into objects. An object tries What is the difference between procedure
to resemble real world objects: it has data and it has behavior. For example, let’s programming language, object oriented
programming language and object based
say you want to make a pet store. You can have cats, cats would have data such programming?

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
as color, age, name, breed, and they have behaviors such as run, eat, jump, What is the difference between data and
functionality in object oriented programming?
meow, etc.
What is the difference between methods and
Typically in OOP, you have classes, which describe objects, and objects are functions in object-oriented programming?

instances of classes. For example:  Ask New Question


1 // this describes the abstract concept of a "Cat"
2 // not individual cats In other languages
3 class Cat {
4 // this is the data that cats have ⽇本語で⼊⼒: オブジェクト指向プログラミングと関
数型プログラミングとは、それぞれどのようなもので
5
6
var color;
var name;
すか?2つの違いとは何ですか?
7 var age;
8 var breed;
9 var weight
10
11 // this are the behaviors:
12 void run(x,y) {
13 // code to run to x, y
14 }
15  
16 void eat(food) {
17 // code to eat some food
18 weight = weight + food.weight;
19 }
20 }
21  
22 // now these represent individual cats:
23 var snowflake = new Cat();
24 snowflake.color = White;

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
25 snowflake.name="Snowflake";
26 snowflake.age=3;
27  
28 // here is a second cat
29 var garfield = new Cat();
30 garfield.color=Orange;
31 garfield.name="Garfield";
32 garfield.age = 7;
33 garfield.weight=40;
34  
35 // lets put snowflake on the left:
36 snowflake.run(0, 0);
37 // and lets tell garfield to move to the right:
38 garfield.run(2, 0);

Functional programming

In functional programming, your program is a function, as in the mathematical


sense. A function receives one or more values and produces another value.
Notice that in the mathematical sense, a function always returns the same thing
for the same value, and that is true in functional programming.

To define a function, you can use other functions. You can even use the same
function to define the function (recursion).

Suppose you want a program that tells you how many letters are in a string, you
would write a function like this:

1 length "" = 0
2 length (x:xs) = 1 + (length xs)

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
This defines a function called length. Length of an empty string is simply 0,
length of x:xs (the letter x, concatenated with the string xs) is 1 + the length of
the rest of the string.

Differences

There are languages that are both object oriented and functional. But in general,
OOP deals with objects and how they change their state based on their
behaviors. Functional deals with functions, state never changes.
1.6k Views · View Upvoters

Promoted by DatadogHQ.com
Get to the root cause of Java performance issues.
Datadog APM provides distributed tracing and real-time analytics for Java apps.
Free 14-day trial.

Learn more at datadoghq.com

Related Questions More Answers Below

Object-Oriented Programming: What is the difference between a function and a method?

What is the difference between object oriented programming and non object oriented
programming?

What is the difference between object-oriented and procedure-oriented programming?

What is functional programming and oriented functional programming?

What's the difference between Object Oriented Programming and Procedural


Programming?

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
 Ask New Question

Richard Kenneth Eng, Used Fortran, Tandem TAL, C/C++, C#, Obj-C, Java,
Smalltalk, Python, Go
Answered Sep 28 · Author has 10.4k answers and 14.7m answer views

They are programming paradigms, or styles of programming. Their definitions


are a bit fast and loose, but basically:

object-oriented programming (OOP) focuses on decomposing a


programming solution into objects (cohesive units that consist of
private state or data, as well as the methods or functions that operate on
the data).

functional programming (FP) focuses on decomposing a programming


solution into pure functions that can be passed around as arguments
and returned from other functions.

By some definitions, FP must also marry with immutability (variables or state


may not change once initialized). Functions must be referentially transparent
(for the same input arguments, the return value is always the same).

By some definitions, OOP must also support inheritance (objects may acquire
the same data and methods from its parent object).

OOP must also support polymorphism (the method or function name may refer
to a number of different functions, and the choice of which one to call is made
on the basis of what object is calling it).

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
The essential difference between the two is polymorphism. Otherwise, there is
practically no difference in how functions are called:

1 f(o); // functional
2 o.f(); // object-oriented

The two systems are perfectly orthogonal and, thus, can be used together. They
are compatible!
1.4k Views · View Upvoters · View Sharers

Hieu Lam Tri, Software Engineer


Answered Sep 21 · Author has 65 answers and 10.7k answer views
Originally Answered: What is the difference between object-oriented and functional programming?

To answer this question fully, it should actually very long and you just actually
understand by doing both OOP and functional programming and it takes times,
could be several months or couple of years.

But in short, I like this comparison from a famous leader in our field

OO makes code understandable by encapsulating moving parts. FP makes


code understandable by minimizing moving parts.

So in OOP you deal with encapsulation, inheritance and polymorphism. The


first class citizen in oop world are objects. You hide the states inside a class and
provide mutator to outside worlds. While in functional programming, the
fundamental concepts is immutable, pure functions, function composition and
high order functions. And the first class citizen is function.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
85 Views

Promoted by Gauge
Low maintenance test automation.
Gauge is a free and open source test automation framework that takes the pain
out of acceptance testing.

Start now at gauge.org

Anton Carver, former Staff Software Engineer at Google (2003-2016)


Answered Sep 21 · Author has 4.6k answers and 749.3k answer views
Originally Answered: What is the difference between object-oriented and functional programming?

Neither term is particularly well defined because if you look at the multitude of
languages which claim to be in a particular category you tend to find similarities
and differences which make the boundaries quite difficult to distinguish. So
what I will say is at a higher level than programming languages and goes more
toward programming philosophy.

In software engineering, a key objective is to decompose a problem into


manageable units. These manageable units may be called modules or
components or have a more specific name within a particular paradigm. For the
sake of brevity, I will refer to them as modules. In principle, the objective of
modularity is the same, to increase coherence and to reduce coupling.

In functional programming, the modular unit is a function and in object-oriented


programming, the modular unit is a class. Overall functional programming

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
concentrates on composing functions whilst object-oriented programming has a
greater focus on hiding implementation details in order to reduce coupling.

There are lots of other things which can be said, but they tend to fall into the
areas where the boundaries are less clear.
75 Views

Dev Dasani, Diploma in Computer Engg from Government Polytechnic ,porbandar


Answered Apr 5
Originally Answered: What is the difference between functional programming and object-oriented
programming?

Object Oriented Programming:-

Object Oriented programming is a programming in which you program using


objects to represent things you are programming about. These object could be
data structures. These objects have data about them in attributes. These
attributes can manipulated using methods or functions. Example languages are
C++, Python, Java, C#

Functional Programming:-

Functional programming is a form of programming used to avoid changing state


and mutable data. In functional programming the output depends on the
arguments given to the function.
308 Views

Eliézer José Da Silva Rios, Owner (2015-present)

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Answered Apr 5
Originally Answered: What is the difference between functional programming and object-oriented
programming?

Two main reasons why object oriented was invented: uses less memory and
avoids inconsistencies whem many players design the same software package.
Simple as that.
287 Views · View Upvoters

Related Questions

What is the difference between structured programming and object-oriented


programming?

What are the advantages of functional programming over object-oriented programming?


What are some languages that are mainly functional?

What is the difference between procedure programming language, object oriented


programming language and object based programming?

What is the difference between data and functionality in object oriented programming?

What is the difference between methods and functions in object-oriented programming?

Are functional programming languages compiled differently than object-oriented


programming languages? Is there still a need for the heap?

What is object oriented programming services? What are the features of object oriented
programming services?

What concepts in Java have silly pretentious names like "dependency injection" but are
superfluous in a more advanced language like Haskell?

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
What is the difference between object-oriented programming and OOAD?

What is the difference between object oriented programming and other programming?

What is difference between object oriented programming language and object based
programming language?

What does the sentence about Haskell "Haskell's laziness lets us define a new control
structure just by defining a function." mean?

What is composition in object-oriented programming?

How important is object-oriented programming? Why?

What is inheritance in object-oriented programming?

 Ask New Question

About · Careers · Privacy · Terms · Contact

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

Potrebbero piacerti anche