Click to See Complete Forum and Search --> : Just a thought about OOP vs. Functional Programming.


jemfinch
07-11-2001, 04:35 PM
I had an epiphany today about programming paradigms. For those bored enough to read, well, here it is:

My 56 day waiting period between blood donations ran up a few days ago, but I couldn't remember which day it was, exactly, so today I called to make sure I was eligible to give blood. Here's the conversation:

Secretary: "Hoxworth Blood Center, Dorothy speaking, may I help you?"
Me: "Hi, I need to find out if I'm eligible to give blood."
Secretary: "What's your name?"
Me: "Jeremy Fincher"
<time passes>
Secretary: "Ok, can I have your social security number?"
Me: "Sure, it's 123-45-6789."
Secretary: "Looks like you became eligible June 6."
Me: "Thanks, I'll be there within the hour!"

I got to thinking after this interchange about how programming paradigms can represent human life. What I realized is that humans are functional creatures not object-oriented creatures. Consider this alternative conversation:

Me: "Hi, I'm Jeremy Fincher."
Secretary: "Yes?"
Me: "I'd like to know if I'm eligible to give blood."
Secretary: "What was your name again?"
...

Had I introduced myself by the object I am (Jeremy Fincher, instance of class Person,) rather than the function I wanted "is_eligible : int -> bool = <fun>" the conversation would've been a bit more broken and certainly less intuitive.

So this is the basis for my proposition that humans think functionally, not object-orientedly. It may be weak support, but hey, I'm bored, and I like functional languages :)

:D

Jeremy

EyesWideOpen
07-11-2001, 04:42 PM
You know what's funny? My friends always get on me because of what I say when I make a phone call to one of their houses: "Hi, this is Curtis. Is so-and-so there?" They say I am the only one who does that instead of just asking for the person first and giving my name if/when they ask for it. I say why even give the person on the receiving end a chance to question who they're talking to? Just let 'em know up front and cut out the inevitable "Who's calling?" question.

Stuka
07-11-2001, 05:51 PM
Are you sure you didn't do it this way:
if (bloodCenter.isEligible(jemfinch){
jemfinch.donateBlood(now);
}
Looks pretty OO to me.... :D

njcajun
07-11-2001, 06:04 PM
hmm...

Just a thought, but I know an academic-type and I've read in books that in order to be good at OOP, you should certainly be able to write GOOD functional code FIRST.

Also, while we all deal with objects daily, which makes an argument for OOP ( I guess ), we ONLY deal with them in the course of performing some FUNCTION.

I've programmed in Java, but I tend to stick to the (more) procedural languages. In the end, the code generally reads pretty much the same way. Just a matter of whether you're looking for a function definition or a class definition. To me, procedural is a bit more intuitive from a development point of view. From a design perspective, a lot of my pseudocode could result in either a function OR object based program.

Those are my (random) thoughts.

bdg1983
07-11-2001, 06:37 PM
I don't like to do a lot of design, therefore I like OOP. I may sound insane, but here is my reasoning:

I need to do A. A involves X, Y and Z. Doing it functionally, I get a big long program divided into X, Y, and Z, but they all have to interact, and I have to think about how they interact while I am making them interact. With OOP, I can write a class Z with the necessary functions, a class Y based on Z, with its necessary functions, nad the main program X, which does nothing but call the functions of Y.

Because I have split it up into so many smaller bits, I don't have to write anything down, and don't have to keep it all straight in my head at the same time. This pleases me.

Of course, functional programming can be done similarly, but I don't find it as easy to keep all the parts separate. I generally find that when I do things OO, they end up far better organised.

Strike
07-11-2001, 07:21 PM
Sounds to me like the attribute isEligible is attached to YOU, the object (an instantiation of FunctionalProgrammer). The OOP conversation would have been:

You: "Hi, I'm Jeremy Fincher."
Secretary: "Yes?"
You: "I'd like to know if I'm eligible to give blood."
Secretary: <punches in name, brings up info about Jeremy Fincher> "Looks like you became eligible June 6."

bugfix
07-11-2001, 08:52 PM
Are you not an object that has inherited properties from the 'person' object? All people share common characteristics, each have a name for example. In turn, each person object is inherited from the 'mammal' object which is in turn derived from the 'animal' object, and so forth down to cell's and molecules. Every animal has limbs, for example.

TheLinuxDuck
07-12-2001, 10:56 AM
This is by far one of the oddest serious threads, and also the most interesting.

(^=

I agree with Strike that isEligible would be a method of the person. Think of it this way.. let's say that you were in another state that didn't have access to your donation records here. If you called isEligible from that out of state object, they would not be able to answer your question, because the in-state donation facility is the one who keeps the records of when you last donated. However, you should be carrying a donor card that lists each donation date on it, so that there would be no question as to your next available donation date. That way, you would say:

jemfinch.isEligible()

:which would examine the last date value of:

jemfinch.lastDonateDate


And, the donate method would be inherited from the person object, but would take the object of the place that in accepting your donation, such as:

jemfinch.donate(CurrentDonationFacility);


I don't necessarily agree with Stuka that the donate method should accept a time. Instead, the person object should monitor the status of what activity jemfinch is currently involved in. Once this object has finished it's current task (and any other items necessary to donate are fulfilled), the donate method can then be called.

(^=

This is interesting! (^=

Qubit
07-12-2001, 12:23 PM
Just think what would happen if that conversation would have been in C. You'd have to pass your address and then the operator would have to perform some clever pointer arithmetic on it, which would make her end up bugging the neighbours or even the rest of the street for blood. This error would leave the operator totally confused and incapable of performing any more tasks, leading to the crash & downfall of the blood center. Within minutes this seemingly small error would propagate through systems throughout the world and cause havoc everywhere. My God! It would murder us all!!

[ 12 July 2001: Message edited by: Glaurung ]

Rob 'Feztaa' Park
07-13-2001, 05:49 PM
Just thank god that the human brain isn't coded in C, then :)

Stuka
07-14-2001, 12:59 AM
Leave it to TLD to spend time analysing my off the cuff, flippant remark and developing some solid design that shows me up! Tell ya what, Duckie, you keep this up and we'll make an OO coder out of you yet!

pdc
07-16-2001, 04:21 AM
OO is a team sport. The teams develop class libraries for team use. All for one and one for all. But, I code alone, all by myself, you know I code alone, just to be by myself ;)

Paul