3 ms·
Most OO languages are based on no theory, while every FP language can trace its roots to the lambda calculus. Functions compose and abstract very well, leading
by daniel_yokomizo 18y ago
Most OO languages are based on no theory, while every FP language can trace its roots to the lambda calculus. Functions compose and abstract very well, leading to simpler and more expressive designs. In OOPLs the unit of abstraction is the class, usually these aren't even first class citizens, the syntax is usually too heavyweight for casual use (imagine a FPL where it takes as many lines of code to declare an anonymous function as it takes to declare an anonymous class in Java). Even Smalltalk and Self use blocks (i.e. closures or lambdas) instead of providing some lightweight class/object literal notation.
GoF patterns were created to solve these problems of OOPLs. If you're trying to do FP in a language without higher order functions and algebraic data types you'll have to come up with dozens of design patterns to express simple things as folds or pattern-matching.
OTOH a hypothetical OOPL with higher-order classes and a lightweight syntax for anonymous object/class literals would provide combinators for almost (if not all) GoF patterns and this wouldn't be an issue. It's not FP that replaces GoF patterns, good languages with a solid theoretical basis replace GoF patterns, independent of the paradigm.
- silentbicycle 18y ago> Most OO languages are based on no theory Smalltalk is based on the same computational theory as Lisp. See: The Early History of Smalltalk (http://gagne.homedns.org/%7etgagne/contrib/EarlyHistoryST.html http://gagne.homedns.org/%7etgagne/contrib/EarlyHistoryST.ht...), search for "to really understand LISP". (It's a scanned and OCR'd article, so there are strange typos.) Unfortunately, you're ultimately correct: "most [popularly used] OO languages" these days seem to be based on tearing off a handful of Smalltalk's object-based theory of computation, duct-taping it on C, and seeing what happens. You can have OO languages with very elegant theoretical foundations (Smalltalk, Io, Self), including systems handling Classes as first-class objects (sometimes called a "Meta-Object protocol"), but most people associate OO with C++ and Java. > Even Smalltalk and Self use blocks (i.e. closures or lambdas) instead of providing some lightweight class/object literal notation. This really is key: the language doesn't require you to create a full anonymous class when sending a message/anonymous function would do. Also, blocks aren't evaluated unless their message is sent, which means you get a good syntax for lambdas and basic lazy evaluation for free. Those, along with dynamic typing, make most of C++ OO-style awkwardness vanish.
- omouse 18y ago"Even Smalltalk and Self use blocks (i.e. closures or lambdas) instead of providing some lightweight class/object literal notation." Blocks are objects! You can use them with various methods and they have state too! The syntax is the lightweight class/object literal notation! Check out the class `BlockContext`.
- jefffoster 18y ago> Most OO languages are based on no theory That's just not true. "A Theory of Objects" is a good introduction. See http://lucacardelli.name/TheoryOfObjects.html http://lucacardelli.name/TheoryOfObjects.html