Question:
What is the difference between function oriented programming and object oriented programming ?
2013-10-26 04:44:28 UTC
What is the basic difference between function and object?
Seven answers:
2013-10-26 11:07:04 UTC
in functional programming

every "program" or "program part" has its own function



but

in object oriented programming

other "programs" or "program parts" are dependent on a MAIN "program's" or MAIN "program part's" function











lol
Pradeesh Bm
2013-10-26 12:15:24 UTC
In function oriented program, an entire program is split into number of function, each has given some specific task and each does it's task and return the values when it is called by other function in the program.

Functions are arranged into hierarchical structure in a function oriented program. Where there must be a root/head function, which

is the main function of entire program where program execution begins from this function. Thus a problem can be solved by Main function calls it's subordinates and subordinates call it's subordinates and so on.



In Object Oriented Programming(OOP) paradigm, an entire program is divided into several number of objects which are originated by it's class and objects communicate with each other by MESSAGE PASSING technique. In object oriented programming, there must be a main/root class which contains a main method, where the execution begins. Data encapsulation, abstraction is the main goal of every object oriented program.
I Don't Eat Vodka
2013-10-26 11:51:28 UTC
On a binary level - next to none (everything you can do in c++ you can do in c or assembly). On a higher level, object oriented code often looks neater and is less verbose as "classes" are used to instantiate complex data structures. Classes have members (primitive data) and functions. Functions are shared by objects of the same class*, however each new object of a class gets it's own copy of the members.



* There is an implicit pointer ("this" pointer) passed as an argument when an object calls own of its methods.
Black
2013-10-28 11:16:51 UTC
Object-Oriented Programming



In OO programming, everything is an object with two aspects: data and behavior. Objects have data (fields, members, attributes, etc.) which are either simple date types (int, String, boolean, etc.) or are objects themselves. You can get and set these values any time you can get a handle on the object, assuming the object implements a way for you to be able to do that (either directly or through accessor methods).



For example, an object in Java might look like this:



1

2

3

4

5

6

7

8

9

10

11

12

13

14

public class Person {

private String name;



public Person() {

}



public void setName(String name) {

this.name = name;

}



public String getName() {

return this.name;

}

}

In this example, I can set the “name” attribute on a Person object whenever I want. Any other piece of code could, too. A particular instance of Person may or may not have a value for “name.” A particular instance of Person will remain in memory for as long as something keeps a reference to it, or until the application shuts down. I can have one part of my code pass a reference to this object to another part of my code. In fact, typically one part of code would set the “name,” pass the reference to of the object to another part of code which would then get the value of “name” off of that object.



In OO programming, the entire system is basically a huge state machine, where objects are created and attributes set, and then the objects are passed around or referenced by other code. The application keeps track of all the object in memory and program execution passes from one object to another, setting data on objects along the way. And programmers are all too familiar with what happens when program execution is attempted on an object that doesn’t actually exist: the Null Pointer Exception.



All sorts of best practices have evolved around creating maintainable, stable, and performant applications based on the characteristics of OO programs. However, in functional programs, the characteristics are different. So not only are there different best practices, the best practices in OO may be worst practices in functional programming.



Functional Programming



There are no objects in functional programming that have attributes and behavior (at least not in XQuery). Data and code are totally separate. Functions control program execution, and while they can receive data in, they themselves do not have fields or attributes. Functions operate on data and pass the data around by value. Once a function passes some data to another function, that’s it. The sending function cannot keep a reference to the data; it passed the data. The receiving function cannot even modify the data. It can, however, create a new copy with modifications, and send that to another function or return it back to the calling function.



Some of the advantages of Functional Programming are:



Nothing can change your data. Once you get it, you’ve got your copy and it’s yours. Nothing can mysteriously change it while you are operating on it. Conversely, a function cannot affect data other than what it received (no side effect).

It’s threadsafe. There are no concurrency issues since nothing can have a reference to the same data. There’s no way for one function to interfere with the data in another function. And there’s no way for code to have stale references.

No Null Pointer Exceptions. NPEs happen when a piece of code knows the definition of an object (its class) but makes the mistake of trying to invoke methods on a non-existent instance of that class. In functional programming, there are no object instances of code. Function signatures are checked statically and then called, so there’s no chance of a code instance not existing, once those functions have been imported.

Expressions can be compounded. This one might take a little effort to grasp at first. Since there are no instances of objects, and since all data is always passed by value from one function to another, then you can have once function call another function and so on without having to worry about instantiating objects or checking for null values. I can pass a string value to substring function to a concatenation function to a parsing function to a date constructor to a date formatter, etc. So my code can be made of compound expressions that elegantly build the logic I need, rather than having to write a new function (or object or method) that does what I want it to do.
2013-10-26 11:49:20 UTC
In OO programming, the entire system is basically a huge state machine, where objects are created and attributes set, and then the objects are passed around or referenced by other code. The application keeps track of all the object in memory and program execution passes from one object to another, setting data on objects along the way. And programmers are all too familiar with what happens when program execution is attempted on an object that doesn’t actually exist: the Null Pointer Exception.



Objects are a combination of both data and logic. You could decide to create an object solely to contain data (like a Data Access Object), or you could decide to create an object that has no data, ie. attributes (like a utility class), but they are still objects and you still must define a class for them and instantiate them.



All sorts of best practices have evolved around creating maintainable, stable, and performant applications based on the characteristics of OO programs. However, in functional programs, the characteristics are different. So not only are there different best practices, the best practices in OO may be worst practices in functional programming.



Functional Programming



There are no objects in functional programming that have attributes and behavior (at least not in XQuery). Data and code are totally separate. Functions control program execution, and while they can receive data in, they themselves do not have fields or attributes. Functions operate on data and pass the data around by value. Once a function passes some data to another function, that’s it. The sending function cannot keep a reference to the data; it passed the data. The receiving function cannot even modify the data. It can, however, create a new copy with modifications, and send that to another function or return it back to the calling function.



Some of the advantages of Functional Programming are:



Nothing can change your data. Once you get it, you’ve got your copy and it’s yours. Nothing can mysteriously change it while you are operating on it. Conversely, a function cannot affect data other than what it received (no side effect).

It’s threadsafe. There are no concurrency issues since nothing can have a reference to the same data. There’s no way for one function to interfere with the data in another function. And there’s no way for code to have stale references.

No Null Pointer Exceptions. NPEs happen when a piece of code knows the definition of an object (its class) but makes the mistake of trying to invoke methods on a non-existent instance of that class. In functional programming, there are no object instances of code. Function signatures are checked statically and then called, so there’s no chance of a code instance not existing, once those functions have been imported.

Expressions can be compounded. This one might take a little effort to grasp at first. Since there are no instances of objects, and since all data is always passed by value from one function to another, then you can have once function call another function and so on without having to worry about instantiating objects or checking for null values. I can pass a string value to substring function to a concatenation function to a parsing function to a date constructor to a date formatter, etc. So my code can be made of compound expressions that elegantly build the logic I need, rather than having to write a new function (or object or method) that does what I want it to do.

It’s well known in the Java world that stateless applications will perform better than stateful ones, everything else being equal. Enterprise Java Beans and web apps are often designed so that they do not need to maintain state information across requests if possible. In functional programming, there’s really no way to maintain state in memory (although you could write it to the database). Since there are no references to objects, there is a built-in performance advantage. Because of this, you can combine and compound several functions and still maintain high performance.



One thing that programmers new to functional programming have to keep in mind is that the only data you have to work with is that which is passed into the function, and the only way you can communicate anything from the function is in the return value. This forces you to think of exactly what your function should do since it can only return one result or sequence of results. You also cannot write functions that simply “do something” without returning a result. That would be violating the principle of “no side effects.” This is a mental shift that the programmer must make: from writing statements that do something, to writing expressions that return something. It might sound simple, but I think there are important fundamental differences in mindset and that’s what is necessary to make the paradigm shift.
sreenivas j
2013-10-26 12:02:21 UTC
Very simply, In a function the main task of the program is performed and the data are declared separately. for ex.

function test()

{

cout<<"welcome";

}

you have to call the function as many times as you need.

test()

test()

In a class, it will be a separate entity.

class test()

{

void print()

{

cout<<" Welcome";

}

}

now you have to create the instances of the class in main function.

test a,b,c.

a.print()

b.print()

c.print()

Hope you got it.
?
2013-10-26 11:49:08 UTC
http://wiki.answers.com/Q/What_is_the_difference_between_object_oriented_programming_and_function_oriented#slide1


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...