On Fri 27 Dec 2013 at 11:40:45AM -0800, Mark Engelberg wrote: > On Fri, Dec 27, 2013 at 11:03 AM, Gary Trakhman > <gary.trakh...@gmail.com>wrote: > > > Why should functions share information? > > Maybe I'm the odd one out, but every project I've done has at least a few > bits of info shared by many functions. It might be something like > BUFFERSIZE or NUM-THREADS or DATABASE_URL.
In OO systems we typically have an Application class with a constructor that receives a map of configuration values. This allows more flexibility than defining static constants as the methods of our Application class close over the instance values. We can achieve the same thing in Clojure, but creating closures over dynamic configuration values is difficult to reconcile with REPL driven development. Typically then, the Clojurist chooses to store these instance values in vars, which creates the tension described in this thread. Stuart Sierra has been thinking quite a bit about this issue, and I think he's developed a great solution: https://github.com/stuartsierra/component/ Designing a system as outlined above results in a modular application with the benefits of an instance constructor, while still allowing easy access from the REPL via a single var bound to the current running instance of the application. I encourage everyone to look into it; I have had great success with it so far. (Thanks Stuart!) guns
pgp8B_Qd2JTzv.pgp
Description: PGP signature