The Phill Dellow Experience

Oo Vs Functional Programming

-What is the difference of object oriented programming verses functional programming?

To start with I think a definition of both might be of assistance, but when I see you on the on the side we may find this statement to be in weakness

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A distinguishing feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of "this"). In object-oriented programming, computer programs are designed by making them out of objects that interact with one another. There is significant diversity in object-oriented programming, but most popular languages are class-based, meaning that objects are instances of classes, which typically also determines their type.

What's that really saying?

It's saying that the program is like a TV or a car and it is made up of separately manufactured goods (objects). They may all come from different factories (classes) but they use common materials (data) measured in a common way (procedures, data fields). Summing theses things together, just as in a car or on a TV, creates something, made from different objects that is more than the simple sum of the information and elements they contain. Object-orientated programming looks at build programs out of smaller objects rather than functions.

We have data, this is an object in it's own right, or when it is organised into a field of some description this feild becomes an object. We have functions that can be performed on this data, sometimes refered to as methods and also refered to as objects. In a nutshell, it's how the program is chopped up or the paradigm it is viewed through (and also manipulated), an Object Oriented analysis

Next we've got Functional Programming:

In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time. Eliminating side effects, i.e. changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.

So what does that mean?

It means that it's faster than Object Orientated, that it takes less code and is easier to learn. Things like loops in Object Oriented need to be written in full, where as they can be a higher class (first class) in functional programming meaning that they can be called (run) anywhere in the program by mentioning it's name. They are faster as the complier gets to be choosey about what it runs when, even to the point of running things in parallel, where as in Object Orientated the complier has to run things in the strict order specified by it's object rather than functional outlook

The best summary I've read for the differenct between the two is here at C2.com

"Fp and Oo are good for different kinds of tasks...If I am programming a UI,(user interface), I use OO. If I am doing mathematical programming, I use FP. In the real world, does anyone really do anything different? It's such a shame when someone finds technology that works in one particular situation and then infers it should be used everywhere for everything. Why are so many analytically-oriented people so inflexible? People should apply paradigms in appropriate areas, rather than having a ParadigmPissingMatch". -- anon

Blog Index

CSS Cheat_Sheet

Culture Blog Week 1

Culture Blog Week 3

Culture Blog Week 4

Culture Blog Week 5

Culture Blog Week 6

Culture Blog Week 7

Culture Blog Week 8

Technical Week 1

Technical Week 2

Technical Week 3

Technical Week 4

Technical Week 5

Technical Week 6

Technical Week 7

Phill and Nary pair a web page in an hour

Main Index