[racket] Code Reuse, Object Oriented vs Functional
Just last week I stumbled across this:
"Solving the Expression Problem with Clojure 1.2
Extend preexisting types to new methods, and preexisting methods to new types"
http://www.ibm.com/developerworks/library/j-clojure-protocols/
If that resonates with you, then someone more knowledgable than me
about Clojure might be able to map that onto the similar concepts in
Racket. (Such as, "protocols and multimethods are like generics", and
"defrecord and deftype are like ___".)
p.s. Personally? I spent many years doing OOP in C++. Lately I'm
functional-ish in Racket (to the point of blatantly ignoring the class
portion of Racket). Sometimes the pendulum has to swing to the other
extreme before settling in the middle, just not yet for me in this
case. However if I were doing GUI or simulation things, I'd probably
be leaning back toward OOP for that.
On Thu, Jun 20, 2013 at 2:53 PM, Scott Klarenbach <scott at pointyhat.ca> wrote:
> I'd like to get some feedback from the Racket group regarding Object
> Oriented vs Functional styles. I know this can be a bit of a quagmire, so
> apologies if it's not appropriate to post it here. I just thought I'm
> likely to get some of the more thoughtful replies from this group.
>
> I've read the paper here:
> http://www.cs.rochester.edu/~cding/Teaching/254Fall2001/Assignments/tr98-299.pdf
> which outlines the central problem as having to choose between extensible
> variants (OO) and extensible tools (functional). The paper proposes the
> extensible visitor pattern as a solution, and ultimately rests in the OO
> camp. The next paper: http://www.ccs.neu.edu/racket/pubs/icfp98-ff.pdf goes
> a step further by showing how Racket specific features such as Units and
> Mixins can eliminate the need for the extensible visitor design pattern, and
> again, lands firmly in the OO camp.
>
> In contrast, I've been playing a lot with Clojure and reading Rich Hickey
> (http://www.infoq.com/presentations/Value-Values and
> http://www.infoq.com/presentations/Simple-Made-Easy) and he proposes the
> opposite approach: OO's time has come, and that through powerful functional
> languages you can achieve encapsulation, polymorphism and extensibility in a
> simpler manner without the complexity of OO techniques.
>
> I'm curious as to the opinion of this community regarding Rich Hickey's
> stance on applying immutable values and pure functions to nearly every
> programming problem.
>
> Regarding the first two papers discussing Object Oriented and Functional
> approaches to reuse, I'm wondering:
>
> 1.) Do generic functions (multiple dispatch) in a language not empower the
> functional arguments in the first two papers by Matthias and Matthew (and
> others)? If I can add new functions with the same name that dispatch on new
> variants as they are added, is this not a simple solution to the
> extensibility problem in a functional style? Does this not allow for reuse
> of both the original components and the existing clients?
>
> 2.) Does there exist an obvious class of problems that are better suited to
> an object oriented design vs functional and vice-versa, or is the power of
> such languages as racket reducing the OO vs Functional debate to a religious
> war, whereby both methods achieve reuse and it's just a matter of
> preference?
>
> Thanks a lot.
>
> --
> Talk to you soon,
>
> Scott Klarenbach
>
> PointyHat Software Corp.
> www.pointyhat.ca
> p 604-568-4280
> e scott at pointyhat.ca
> 200-1575 W. Georgia
> Vancouver, BC V6G2V3
>
> _______________________________________
> To iterate is human; to recur, divine
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>