Google Answers Logo
View Question
 
Q: object oriented programming vs function oriented (short and sweet please) ( Answered,   1 Comment )
Question  
Subject: object oriented programming vs function oriented (short and sweet please)
Category: Computers > Programming
Asked by: crisis-ga
List Price: $12.00
Posted: 21 May 2003 17:23 PDT
Expires: 20 Jun 2003 17:23 PDT
Question ID: 207071
First please let me explain that i am a complete programming novice. I
have no programming skills and very little conception of how
programming works.

A course i have been taking includes a module which is teaching us
about aspects of UML and how it is useful in designing object oriented
programming. This specific topic i can understand. However, due to my
lack of knowledge about programming in general, i have a lack of a
framework within which to put all this information, and this is what i
am looking for here.

Specifically my question(s) is this. 

In simple terms, what is the key difference between function oriented
programming and object oriented programming?

Why has the whole world moved from FOP to OOP?

When the whole world was still using FOP what was the UML equivalent?

thanks
Answer  
Subject: Re: object oriented programming vs function oriented (short and sweet please)
Answered By: jeanluis-ga on 21 May 2003 18:56 PDT
 
Very interesting question, I will attempt to answer all of your
questions here, but if I am unclear, or lacking on any point please
let me know, and I will try to clear things up. Just for your
information I am hold a BS in computer science and have been
professionally employed as such for ~5 years.

Ok here we go:
Differences between functional and objected oriented programming can
be summed up as follows:
In object oriented programming everything (or almost everything) is
treated as an object that can be modified and that can perform tasks,
or in OOP speak one might say objects have state and behavior. What it
buys you (among other more advanced things) is: modularity,and data
hiding.

Here is an example: You might have an object that models a ball, from
above the ball can be modified (i.e. you can change its state) for
example you may be able to change the color of the ball. It can also
perform tasks (i.e. it also has behavior) for example the ball can
roll, or be thrown. As an object it is bundled neatly in a package
that provides methods to change the state of the ball, and to make the
ball perform actions. This package is usually called a module, in
addition to the methods used to change state, and perform actions, the
module also has data that is used to store any state information
needed.

Because this module is a complete package that models your object
competely, the module can easily be reused in many different
applications. Once it is wirtten and working anyone should be able to
use the module without fully understanding internals. For examplea all
one needs to know is that they want a red ball to throw. :)

Here is a good resource on OOP:
"Object-Oriented programming concepts"
http://java.sun.com/docs/books/tutorial/java/concepts/


In functional programming what you have basically are a set of
functions each of which performs a task. Selectively executing these
function results in the solution to the problem at hand.

For example you might have a function that takes the coords. of a
square computes the area, and you may have another function that
computes the area of a triangle. By executing the square function 6
times you could compute the area of a cube. Or by executing a
combination of the square and triangle functions you could compute the
area of a rhomboid. As you can see you can build quite complex systems
based on simple functions.

Technically choosing OOP of FOP (or vice versa) you can always
accomplish the same results in either paradigm, however what may be
very easy to do with an OOP approach may prove to be very difficult in
FOP, and the converse may also be true depending on the problem.

Which leads to: Why has the whole world moved from FOP to OOP...
Welp this one is simple, it hasn't (in my opinion). Much of the world
is moving to OOP, and OOP is getting all the press of late. But there
is still a TON of work going on in the FOP world. But I digress, that
is a different debate.

I think the examples above may have already shed some light on this
question, but simply put OOP makes it easier to conceive very large
complex systems. Because it gives the developers the ability to break
the system down to small tangible.. uhh.. objects... :) which can be
designed, developed, and tested independently.

In a functional paradigm what invariably happens as a large system
grows: it becomes a huge pile of functions. All of which are
interconnected, and dependent on each other. Which means if you change
one function you break 10 others, it becomes impossible to manage. A
*good* large program written in a functional language is usually
designed with OOP principles in mind. (i.e. it is designed as a set of
modules that are not inter-dependent on other modules)

What was the pre-UML UML? well there were (and are) many modeling
languages out there. Many people used pen, and paper to draw flow
charts, diagrams, or write pseudo-code. I have to confess that
modeling languages are not my strong suit, but here are some links on
their history:
"History of UML"
http://pigseye.kennesaw.edu/~dbraun/csis4650/A&D/UML_tutorial/history_of_uml.htm

"UML"
http://www.inforingpress.com/computer_information/uml.htm

I hope this helps, please let me know if you have any other questions:
thanks,
--jld
Comments  
Subject: Re: object oriented programming vs function oriented (short and sweet please)
From: dls_spy-ga on 28 May 2003 18:08 PDT
 
I think the answer goes into OOP pretty well, but kind of missed on
functional programming.

There are (as I learned, anyway), four major programming paradigms:

Imperative (which is, I believe, what the asker was asking about)
Functional
Logic
Object-oriented

I found a good description of each on the following web page:

http://www.cs.auc.dk/~normark/prog3-02/html/notes/paradigms_themes-paradigm-overview-section.html

While I agree that imperative (C, etc...) programs can be difficult to
maintain if you're not careful, studies have shown that functional
(caml, scheme, lisp, haskell) programs can often be easier to maintain
than many OO systems.  OO targets reuse by the abstract Object
concept, and it can be done very succesfully, but there are many areas
that object reuse fails.

It really depends on what your requirements are, but there is a lot
going in functional programming.  Haskell (www.haskell.org) is a
particularly interesting one in that programs can be expressed very
simply, yet generically at the same time (i.e. ``sort'' doesn't have
to be implemented for every type of data you create).  OCaml
(http://caml.inria.fr/) is also very interesting in that it's a
strongly-typed functional programming language that also allows for
OOP while being insanely fast at runtime.

My strong recommendation to anyone persuing programming for fun or
profit:  Learn lots of different ways to solve problems.  In
particular, learn scheme (or another lisp), learn haskell, learn
smalltalk, learn java, learn python...if you feel you know enough
programming to not kill yourself, learn perl.

I'm a professional java programmer, but I'm hesitant to hire people
onto my team who don't understand functional programming.  Java, in
particular, seems to be a balance of OO and imperative (contrast
smalltalk for OO and fortran for imperative).  There are functional
ways to solve problems really easily that can be applied to java, but
people who aren't familiar with lambda calculus will proceed to do
things a difficult and hard to maintain way.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy