Re: How to handle configuration in Clojure?
There's also Jig : https://github.com/juxt/jig Jig's recommendation is for configuration to be held in EDN files. I much prefer EDN over environment variables. Environment variables feel awkward when there you have lots of configuration, usually in the form of a tree. Usually it makes sense to have one configuration file per environment. That can make it hard to keep configuration files up to date, so judicious use of the #=() Clojure reader macro can allow you to programmatically deviate from a default configuration - often the delta from a default configuration is more informative. There are more details in Jig's README.md file. I agree with the comments against using dynamic vars. They reduce the ability to reason about functions and are precarious when dealing with threads - binding conveyance is tricky and small mistakes can lead to elusive bugs. I pass configuration as a single argument into types/records that declare lifecycle methods. I have found this pattern to serve me well in over a dozen projects. Since stumbling on this pattern I have had no need to resort to dynamic vars for environment config, and my projects have been smaller, more reliable and easier to reason about. On Tuesday, January 14, 2014 9:04:45 AM UTC, James Trunk wrote: Thanks for all the great links and ideas you have all posted, now I have plenty of reading and thinking to do! I am curious about what you mean by 'thread safety'. Perhaps thread safety is the wrong term, but what I meant was the limitations dynamic binding introduces around thread dispatching, which Stuart Sierra explains in this blog posthttp://stuartsierra.com/2013/03/29/perils-of-dynamic-scope . Cheers, James On Monday, January 13, 2014 7:10:38 PM UTC+1, Stefan Kanev wrote: On 13/01/14, James Trunk wrote: The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). I am curious about what you mean by 'thread safety'. As far as I know, dynamic variables are thread-local, which means that they are thread-safe, at least to some extend. I assume you mean something specific? -- Stefan Kanev ¦ @skanev ¦ http://skanev.com/ If a program manipulates a large amount of data, it does so in a small number of ways. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
I've been using carica (https://github.com/sonian/carica) and have config map like {:dev ... :prod ...} and just using a single environmental variable to determine which of those config maps to use. On Friday, January 17, 2014 5:06:31 AM UTC-8, Malcolm Sparks wrote: There's also Jig : https://github.com/juxt/jig Jig's recommendation is for configuration to be held in EDN files. I much prefer EDN over environment variables. Environment variables feel awkward when there you have lots of configuration, usually in the form of a tree. Usually it makes sense to have one configuration file per environment. That can make it hard to keep configuration files up to date, so judicious use of the #=() Clojure reader macro can allow you to programmatically deviate from a default configuration - often the delta from a default configuration is more informative. There are more details in Jig's README.md file. I agree with the comments against using dynamic vars. They reduce the ability to reason about functions and are precarious when dealing with threads - binding conveyance is tricky and small mistakes can lead to elusive bugs. I pass configuration as a single argument into types/records that declare lifecycle methods. I have found this pattern to serve me well in over a dozen projects. Since stumbling on this pattern I have had no need to resort to dynamic vars for environment config, and my projects have been smaller, more reliable and easier to reason about. On Tuesday, January 14, 2014 9:04:45 AM UTC, James Trunk wrote: Thanks for all the great links and ideas you have all posted, now I have plenty of reading and thinking to do! I am curious about what you mean by 'thread safety'. Perhaps thread safety is the wrong term, but what I meant was the limitations dynamic binding introduces around thread dispatching, which Stuart Sierra explains in this blog posthttp://stuartsierra.com/2013/03/29/perils-of-dynamic-scope . Cheers, James On Monday, January 13, 2014 7:10:38 PM UTC+1, Stefan Kanev wrote: On 13/01/14, James Trunk wrote: The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). I am curious about what you mean by 'thread safety'. As far as I know, dynamic variables are thread-local, which means that they are thread-safe, at least to some extend. I assume you mean something specific? -- Stefan Kanev ¦ @skanev ¦ http://skanev.com/ If a program manipulates a large amount of data, it does so in a small number of ways. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
Thanks for all the great links and ideas you have all posted, now I have plenty of reading and thinking to do! I am curious about what you mean by 'thread safety'. Perhaps thread safety is the wrong term, but what I meant was the limitations dynamic binding introduces around thread dispatching, which Stuart Sierra explains in this blog posthttp://stuartsierra.com/2013/03/29/perils-of-dynamic-scope . Cheers, James On Monday, January 13, 2014 7:10:38 PM UTC+1, Stefan Kanev wrote: On 13/01/14, James Trunk wrote: The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). I am curious about what you mean by 'thread safety'. As far as I know, dynamic variables are thread-local, which means that they are thread-safe, at least to some extend. I assume you mean something specific? -- Stefan Kanev ¦ @skanev ¦ http://skanev.com/ If a program manipulates a large amount of data, it does so in a small number of ways. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
On 14/01/14, James Trunk wrote: I am curious about what you mean by 'thread safety'. Perhaps thread safety is the wrong term, but what I meant was the limitations dynamic binding introduces around thread dispatching, which Stuart Sierra explains in this blog posthttp://stuartsierra.com/2013/03/29/perils-of-dynamic-scope Fair enough. Thanks for the elaboration. -- Stefan Kanev ¦ @skanev ¦ http://skanev.com/ Bringing computers into the home won't change either one, but may revitalize the corner saloon. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
On Monday, January 13, 2014 8:50:54 AM UTC-5, James Trunk wrote: I've been investigating how to handle configuration in a Clojure application/library, and have discovered two main candidates: dynamics vars and argument passing. I would suggest you add Environment variables to your list.Also, check out the 12 factor app (especially the parts about configuration). http://12factor.net/config I use env vars for most things in my clojure deploys, and it's easy to manage/move/everything. YMMV. -jbs -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
On 13 January 2014 14:50, James Trunk james.tr...@gmail.com wrote: What is the current best practice for handling configuration? While I haven't tried this myself, this popped up on Planet Clojure a couple of days back: http://tech.puredanger.com/2014/01/03/clojure-dependency-injection/ Whilst DI is not precisely config management, the pattern described in the blog seems applicable. Cheers, Josh -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
There's also this: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/local-io/edn-config/edn-config.asciidoc Joachim -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
https://github.com/james-henderson/nomad can be one option for manage/store a configuration ;) (it uses edn...) Andrey 2014/1/13 Joachim De Beule joachim.de.be...@gmail.com There's also this: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/local-io/edn-config/edn-config.asciidoc Joachim -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Andrey Antukh - Андрей Антух - andrei.anto...@kaleidos.net / n...@niwi.be http://www.niwi.be http://www.niwi.be/page/about/ https://github.com/niwibe -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
Another option is to use leiningen profiles to change the classpath, loading different versions of a (eg) config.clj file in different environments. This lets you `require` the config namespace and refer to config parameters like `config/the-configured-value` Travis On Mon, Jan 13, 2014 at 11:05 AM, Andrey Antukh n...@niwi.be wrote: https://github.com/james-henderson/nomad can be one option for manage/store a configuration ;) (it uses edn...) Andrey 2014/1/13 Joachim De Beule joachim.de.be...@gmail.com There's also this: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/local-io/edn-config/edn-config.asciidoc Joachim -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Andrey Antukh - Андрей Антух - andrei.anto...@kaleidos.net / n...@niwi.be http://www.niwi.be https://github.com/niwibe -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
This got me thinking about Stuart Sierras Component: https://github.com/stuartsierra/component Kristoffer Den måndagen den 13:e januari 2014 kl. 16:22:55 UTC+1 skrev Joachim De Beule: There's also this: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/local-io/edn-config/edn-config.asciidoc Joachim -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
On 13/01/14, James Trunk wrote: The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). I am curious about what you mean by 'thread safety'. As far as I know, dynamic variables are thread-local, which means that they are thread-safe, at least to some extend. I assume you mean something specific? -- Stefan Kanev ¦ @skanev ¦ http://skanev.com/ If a program manipulates a large amount of data, it does so in a small number of ways. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
A middle ground between dynamic vars and passing state through functions that themselves don't need it, but which is needed by functions they call, is to build on top of defprotocol and defrecord, to refactor so that the functions that need configuration state in their operations are defined by protocols, and the state they need is captured in a record, which can then be prepared at initialization time with the necessary information. In this solution, there is still noise in the sense that now protocol functions have to take their record configuration as a first parameter, but the semantic noise in having unused configuration data passing through that first parameter should be relieved. There's a lot more to say here, but the upshot/goal of the refactoring should be that explicit dependencies between the function call tree- organized into protocols- and initialization/configuration state- organized into records- should be nicely revealed. There are reasons that they might not, and then that's a time to look at other state/configuration management approaches like atoms/refs and dynamic vars. Someone else mentioned Stuart Sierra's Component library: https://github.com/stuartsierra/component Stuart seems to have gone furthest in encapsulating this pattern, so his examples are good to think about, even if you don't adopt the library. HTH. On Mon, Jan 13, 2014 at 8:50 AM, James Trunk james.tr...@gmail.com wrote: I've been investigating how to handle configuration in a Clojure application/library, and have discovered two main candidates: dynamics vars and argument passing. The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). The downside to argument passing is noise in the code (especially when you're just passing the config through). Longer and more descriptive names for the config (i.e. not ctx or cfg) make this noise even more painful. Are there any alternatives that I've missed? What is the current best practice for handling configuration? Cheers, James -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
github.com/weavejester/environ/ + environment variables. 12-factor it that way, proxy the environment variables via a config namespace so that configuration values are programmatically generated in case something needs to intervene. On Monday, January 13, 2014 5:50:54 AM UTC-8, James Trunk wrote: I've been investigating how to handle configuration in a Clojure application/library, and have discovered two main candidates: dynamics vars and argument passing. The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). The downside to argument passing is noise in the code (especially when you're just passing the config through). Longer and more descriptive names for the config (i.e. not ctx or cfg) make this noise even more painful. Are there any alternatives that I've missed? What is the current best practice for handling configuration? Cheers, James -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
Example here: https://github.com/bitemyapp/berossus/blob/master/src/berossus/rocks/your/data/config.clj On Monday, January 13, 2014 1:57:06 PM UTC-8, Christopher Allen wrote: github.com/weavejester/environ/ + environment variables. 12-factor it that way, proxy the environment variables via a config namespace so that configuration values are programmatically generated in case something needs to intervene. On Monday, January 13, 2014 5:50:54 AM UTC-8, James Trunk wrote: I've been investigating how to handle configuration in a Clojure application/library, and have discovered two main candidates: dynamics vars and argument passing. The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). The downside to argument passing is noise in the code (especially when you're just passing the config through). Longer and more descriptive names for the config (i.e. not ctx or cfg) make this noise even more painful. Are there any alternatives that I've missed? What is the current best practice for handling configuration? Cheers, James -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: How to handle configuration in Clojure?
+1 for environ as well. I also have combined that with the Stuart Sierra reloaded workflow (started it before Components, don't know if I want to switch). http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded Finding it a great fit, as it's easy to switch out environ variables in your system map when testing very easily, as you pass it all around. Mark On Tue, Jan 14, 2014 at 8:57 AM, Christopher Allen c...@bitemyapp.comwrote: Example here: https://github.com/bitemyapp/berossus/blob/master/src/berossus/rocks/your/data/config.clj On Monday, January 13, 2014 1:57:06 PM UTC-8, Christopher Allen wrote: github.com/weavejester/environ/ + environment variables. 12-factor it that way, proxy the environment variables via a config namespace so that configuration values are programmatically generated in case something needs to intervene. On Monday, January 13, 2014 5:50:54 AM UTC-8, James Trunk wrote: I've been investigating how to handle configuration in a Clojure application/library, and have discovered two main candidates: dynamics vars and argument passing. The downsides to dynamic vars seem to be: hiddenness, thread safety, and more complex tests (binding before each test). The downside to argument passing is noise in the code (especially when you're just passing the config through). Longer and more descriptive names for the config (i.e. not ctx or cfg) make this noise even more painful. Are there any alternatives that I've missed? What is the current best practice for handling configuration? Cheers, James -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- E: mark.man...@gmail.com T: http://www.twitter.com/neurotic W: www.compoundtheory.com 2 Devs from Down Under Podcast http://www.2ddu.com/ -- -- 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 --- 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.