Sorry for the slow response - we've been wrapped up in a gigantic data
migration at work...

On Tue, May 1, 2012 at 4:26 AM, Wolodja Wentland <babi...@gmail.com> wrote:
> It certainly does, but I am none the wiser. I always had the 
> feeling/impression
> that dynamic variables are something to be avoided, but I see them frequently
> in Clojure code I read and therefore have the impression that they are "the
> right thing to do"™ in a couple of instances.

I think the problem is that "good" Clojure style is still evolving and
a lot of the libraries were started a while ago before the "no dynamic
variables" guideline really took hold. That's to be expected in a new
and evolving language.

I don't think clojure.java.jdbc is a very good example of idiomatic
Clojure now but I'm sure it was considered good practice when it was
originally built. I just looked at our codebase at work and the only
things we have that are dynamic are:
* global debug flags (set false, which can be rebound for specific
call trees as needed)
* global vars that defined external integration points (which can be
rebound to test against other integration points: dev / test / prod,
for example)

I could probably reduce those further but five variables out of 4kloc
production code doesn't seem bad (and a couple of those are primarily
for mocking end points for testing - where I could use with-redefs, to
be honest).

> How would you, for example, implement the logging example I quoted above? What
> about handling global configuration (config files, CLI options, ..) ?

Logging is probably a good example because you don't want to have to
pass flags thru your code (that's similar to what we do with our debug
flags). For command line options, I would explicitly pass the map thru
the code because I think that's cleaner in most cases. That said, for
environmental configuration at World Singles, we have a delayed map
for our environment settings and we require/refer that directly into
code that needs it, e.g.,

(let [s @env/my-settings]
  ... (:some-value s) ...)

Neither a dynamic variable nor something passed thru the code.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to