>>41
WTF? You just contrasted ``OOP'' and ``FP''. Do you have any idea how vacuous, confused or retarded such a contrast is? Do you realize the only reason you made this contrast is that our friendly Californian-American snake oil sales men have a new bridge to sell us?
Now, not only does this speak volumes about your web habits, social circles, and judgement, it also gives away that you haven't really been exposed to a large number or variety of programming languages, or that if you have its been very very cursory.
Also, you're just plain wrong:
CL-USER> (defclass dog () ())
#<STANDARD-CLASS DOG>
CL-USER> (defclass cat () ())
#<STANDARD-CLASS CAT>
CL-USER> (defgeneric speak (animal))
#<STANDARD-GENERIC-FUNCTION SPEAK #x18B9E3E6>
CL-USER> (defmethod speak ((animal cat))
(format t "Meow.~%"))
#<STANDARD-METHOD SPEAK (CAT)>
CL-USER> (defmethod speak ((animal dog))
(format t "Woof.~%"))
#<STANDARD-METHOD SPEAK (DOG)>
CL-USER> (defparameter *animals* nil)
*ANIMALS*
CL-USER> (push (make-instance 'dog) *animals*)
(#<DOG #x18B87C8E>)
CL-USER> (push (make-instance 'cat) *animals*)
(#<CAT #x18B86486> #<DOG #x18B87C8E>)
CL-USER> (mapc #'speak *animals*)
Meow.
Woof.
(#<CAT #x18B86486> #<DOG #x18B87C8E>)
Now, I can (without recompiling anything) add new functions over existing data types.
CL-USER> (defgeneric encounter (predator prey))
#<STANDARD-GENERIC-FUNCTION ENCOUNTER #x18BA144E>
CL-USER> (defmethod encounter ((predator dog) (prey cat))
(format t "Dog eats cat.~%"))
#<STANDARD-METHOD ENCOUNTER (DOG CAT)>
CL-USER> (defmethod encounter ((predator dog) (prey dog))
(format t "Dog eats dog.~%"))
#<STANDARD-METHOD ENCOUNTER (DOG DOG)>
CL-USER> (defmethod encounter ((predator cat) (prey dog))
(format t "Cat cannot eat dog.~%"))
#<STANDARD-METHOD ENCOUNTER (CAT DOG)>
CL-USER> (defmethod encounter ((predator cat) (prey cat))
(format t "Cat cannot eat cat.~%"))
#<STANDARD-METHOD ENCOUNTER (CAT CAT)>
CL-USER> (mapc #'encounter *animals* *animals*)
Cat cannot eat cat.
Dog eats dog.
(#<CAT #x18B104C6> #<DOG #x18B10726>)
CL-USER> (mapc #'encounter *animals* (reverse *animals*))
Cat cannot eat dog.
Dog eats cat.
(#<CAT #x18B104C6> #<DOG #x18B10726>)
This also shows off multiple dispatch.
I can also add new type cases for existing functions (again without recompiling anything).
CL-USER> (defclass rabbit () ())
#<STANDARD-CLASS RABBIT>
CL-USER> (defmethod speak ((animal rabbit))
(format t "I am not a rabbit, I am a horse!~%"))
#<STANDARD-METHOD SPEAK (RABBIT)>
CL-USER> (push (make-instance 'rabbit) *animals*)
(#<RABBIT #x18B943DE> #<CAT #x18B104C6> #<DOG #x18B10726>)
CL-USER> (mapc #'speak *animals*)
I am not a rabbit, I am a horse!
Meow.
Woof.
(#<RABBIT #x18B943DE> #<CAT #x18B104C6> #<DOG #x18B10726>)
But now that I've established with high certainty that you are a blog reading, trendroid, fashionista, moron (your use of Haskell should have been enough in retrospect) I have nothing more to say to you.
I can just picture you, talking to your ``modern'' friends:
Eww!! Object-oriented is so totally 1990s! Don't be a square honey and stop wearing that Java! I'm riding the functional programming train, that's where all the big, in hip hunks are. Come join me on carriage Haskell, I know you're a total size queen teehee!
Disgusting.