[racket] Code Reuse, Object Oriented vs Functional

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Thu Jun 20 19:17:24 EDT 2013

Anecdotal...

Racket is a powerful general-purpose algorithmic language, including a 
bunch of great facilities for mini-languages, plus some standard 
libraries (like "racket/class") that support different ``paradigms''.

Early in my career, I did a lot of industry R&D work on methodology and 
CASE for OO analysis/design/programming, as well as a lot of practical 
work using those same methods and tools.  So it was surprising to me to 
find myself no longer using even an OOPL nor always decomposing the 
world into a class-instance object model.

Nowadays, doing most of my development in Racket, I never use Racket's 
OO library, but instead pick&choose conceptual constructions from 
various different ``paradigms'', and implement them using basic Racket 
features.  For example, in the code I am working on in another window -- 
which generates a startup's Web site -- I think of the pages as objects, 
but actually implement them using Racket "struct"s, and populated via a 
minilanguage, with all the metadata and content embedded in the Racket 
source file.  The code is in a functional-esque style, with almost no 
mutations, but I am also conscious of the algorithmic evaluation model.  
The bodies of the pages -- separate from the metadata and stock parts -- 
is marked up in a minilanguage that is s-expressions that is SXML with 
some non-SXML bits added to it: shorthands for things like referring to 
particular pages by ID, and special URI objects (absolute URI that are 
automatically translated to minimal URI relative to the URI of the page 
in which they are referenced).  The site has a 
programmatically-generated navigation bar that works in a desired way 
that off-the-shelf ones probably couldn't do.  This is a small program, 
and I just banged it out quickly to suit the task, not spent weeks on 
it.  It sure beats using some big ``enterprise framework'' that wants 
things done in a bloated and bureaucratic manner yet doesn't really do 
what I want.

Neil V.


Posted on the users mailing list.