Hi Shantanu, that was perfect, thanks. I note that this article only deprecates dynamic scoping in libraries, so my conclusion is that what I am considering is not an antipattern. Indeed, Stuart Sierra says the same:
"Applications can manage their own resources, and only the application programmer knows what the extent of those resources should be. Maybe you can pass it around as a value. Maybe you want to use dynamic binding after all. Maybe you want to stash it in a global state Var. That’s for you to decide." On Wednesday, August 28, 2013 10:55:10 PM UTC-7, Shantanu Kumar wrote: > > Hi Lyn, > > Dynamic vars for resource sharing is not a favored approach due to > performance and several other reasons. This blog post explains it well: > http://stuartsierra.com/2013/03/29/perils-of-dynamic-scope > > Shantanu > > On Thursday, 29 August 2013 07:21:46 UTC+5:30, Lyn Headley wrote: >> >> Hello, if I want to run some sql code in a transaction, I can do >> this (where clojure.java.jdbc is referred to as j): >> >> (j/db-transaction >> [conn dbspec] >> use conn here >> >> But if I have a function I want to call from this transaction, say to >> do a query, then I need to pass in the connection to that function: >> >> (defn query [conn] >> do query on conn...) >> >> (j/db-transaction >> [db dbspec] >> (query conn)) >> >> I am trying to decide whether I like passing in the connection to >> query, or whether I would rather use a binding like so: >> >> (def ^:dynamic *conn*) >> >> (defn query [] >> do query on *conn*...) >> >> (j/db-transaction >> [conn dbspec] >> (binding [*conn* conn] >> (query))) >> >> Looking at the jdbc docs, I notice that this style used to be directly >> supported but is now deprecated. Does that mean it's a bad idea to >> re-implement on top of the supported API, as my example would? Can >> someone explain the tradeoffs involved? >> >> Thanks, >> Lyn Headley >> >> -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
