[racket] Code Reuse, Object Oriented vs Functional

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Jun 20 15:19:14 EDT 2013

1. Yes, extensible dispatch allows for elegant solutions of the 'extensibility problem' that we worked on in the 1990s. Manuel Serrano pointed that out in '99 and again in '00, and by coincidence, we discussed this today in a meeting on generics. 

2. Choose depending on your existing context (language, ide, tools) and needs (how much extensibility do you need now?). If you are writing a product from scratch, choose a tool chain whose language allows and supports FP, class-based OOP, and generics programming. Answering this question in the abstract is a bad idea. 

You may wish to check out the generics library in git head (developed by Eli, Vincent, Asumu, and Claire -- a kind of historic order) to see whether it fits your needs. 

-- Matthias

On 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

Posted on the users mailing list.