workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
Style Question: If I have global-level configuration data, how should I make that accessible to the functions in my program? I can think of 4 ways: 1) Pass ALL configuration data in a single map as an argument to each function that needs some of the config data. 2) Pass ONLY the configuration values that are NEEDED as individual arguments to each function 3) `(declare)` some vars for configuration, then `(defn)` all the functions that need access to them, then start runtime, then populate the config vars 4) Start program, read in config values, then use `(let)` to hold the config values while using `(defn)` to create closures around the config values as needed.
2017-11-07T17:20:22.000069
Sophie
clojurians
clojure
I’m sure there are other ways, too.
2017-11-07T17:20:26.000349
Sophie
clojurians
clojure
Does this make sense?
2017-11-07T17:20:30.000076
Sophie
clojurians
clojure
Does anyone have any wisdom for me here?
2017-11-07T17:20:36.000072
Sophie
clojurians
clojure
I do 1) in combo with using stuartsierra/component which I use to also pass all stateful shared resources in the same map with the config
2017-11-07T17:21:59.000059
Margaret
clojurians
clojure
i’ve been using <https://github.com/weavejester/environ>
2017-11-07T17:26:24.000246
Jonas
clojurians
clojure
Personally my latest project is using <https://github.com/tolitius/cprop> to manage the values (via merging environment, system properties, &amp; a config file of defaults) and storing the result loaded at known times via <https://github.com/tolitius/mount>
2017-11-07T17:29:46.000143
Raul
clojurians
clojure
<@Jonas> I use environ too, but for example if a library needs config, I’d rather pass the config in from my app, rather than putting environ in the library
2017-11-07T17:30:00.000242
Margaret
clojurians
clojure
and it turns out I have a few libraries that need config
2017-11-07T17:30:12.000065
Margaret
clojurians
clojure
same
2017-11-07T17:30:41.000204
Jonas
clojurians
clojure
libraries should avoid imposing too much structure on the consumers of the library
2017-11-07T17:31:07.000315
Jonas
clojurians
clojure
it would be annoying if a library forced you to use environ
2017-11-07T17:32:09.000389
Jonas
clojurians
clojure
I haven’t used any of those. I’ll go check them out.
2017-11-07T17:32:40.000260
Sophie
clojurians
clojure
Thanks
2017-11-07T17:32:49.000411
Sophie
clojurians
clojure
It’s interesting to me that this is such a fundamental task in any programming language, but there are so many libraries to achieve this
2017-11-07T17:33:15.000357
Sophie
clojurians
clojure
I’m thinking, “shouldn’t there be an obvious, idiomatic clojuric way to do this?”
2017-11-07T17:33:48.000206
Sophie
clojurians
clojure
but each of the four ways I mentioned definitely have their own specific tradeoffs
2017-11-07T17:34:13.000310
Sophie
clojurians
clojure
there are lots of different tradeoffs
2017-11-07T17:34:19.000474
Jonas
clojurians
clojure
yea
2017-11-07T17:34:20.000220
Jonas
clojurians
clojure
if clojure was just used for one specific domain, then you might seem more convergence
2017-11-07T17:34:35.000105
Jonas
clojurians
clojure
4) is definitely not “clojuric” at all
2017-11-07T17:34:38.000068
Margaret
clojurians
clojure
we don’t do much data hiding
2017-11-07T17:34:44.000176
Margaret
clojurians
clojure
right, that seemed hideous as I was typing it
2017-11-07T17:34:52.000020
Sophie
clojurians
clojure
for a similar reason, 2 is OK, but most people would prefer 1 to it
2017-11-07T17:35:22.000252
Margaret
clojurians
clojure
and 3 is really just accessor methods, which are also not “clojuric” if we are going to use that word
2017-11-07T17:35:54.000480
Margaret
clojurians
clojure
so that leaves 1, with a maybe on 2
2017-11-07T17:36:01.000048
Margaret
clojurians
clojure
and you don’t need a library to do 1 or 2 - it’s a simple convention using immutable data
2017-11-07T17:36:32.000549
Margaret
clojurians
clojure
i tend to write small apps, but I typically use a form of 3
2017-11-07T17:36:36.000605
Jonas
clojurians
clojure
:flushed:
2017-11-07T17:36:43.000217
Jonas
clojurians
clojure
`(def db-conn (env :db-info))`
2017-11-07T17:37:06.000481
Jonas
clojurians
clojure
and then have a query function that uses the global db-conn
2017-11-07T17:37:24.000569
Jonas
clojurians
clojure
do you use ALL-CAPS in those var names or some other convention to mark them as “coming from outside of this function” ?
2017-11-07T17:37:41.000118
Sophie
clojurians
clojure
or do you just remember “db-conn” is a global thing ?
2017-11-07T17:37:55.000004
Sophie
clojurians
clojure
no all caps
2017-11-07T17:38:11.000266
Kareen
clojurians
clojure
tell me all about it, bronsa
2017-11-07T17:38:23.000324
Sophie
clojurians
clojure
most of the application code doesn’t use the `db-conn`
2017-11-07T17:38:42.000124
Jonas
clojurians
clojure
cause it’s not passed around
2017-11-07T17:38:45.000214
Jonas
clojurians
clojure
the application code will just do `(query "select 1")`
2017-11-07T17:38:57.000066
Jonas
clojurians
clojure
i realize that might be a controversial way to do it, but most apps never outgrow by needing multiple database connections within the same app
2017-11-07T17:40:06.000224
Jonas
clojurians
clojure
and it’s easy to change once/if that’s the case
2017-11-07T17:40:15.000049
Jonas
clojurians
clojure
We used to do 3) when we started out using Clojure (2011) but we've switched to 1) (or 2) for subcomponents) with Component. Much nicer.
2017-11-07T17:40:50.000125
Daniell
clojurians
clojure
Our app has five or six DB connections <@Jonas> :slightly_smiling_face:
2017-11-07T17:41:12.000396
Daniell
clojurians
clojure
:slightly_smiling_face:
2017-11-07T17:41:25.000343
Jonas
clojurians
clojure
So we have a Database Component with a `xyz-db` element for each DB connection (we create connection pools at startup).
2017-11-07T17:41:58.000492
Daniell
clojurians
clojure
also I take it back, 3 isn’t accessor methods (I misread) - but it is singletons which can be a problem
2017-11-07T17:42:04.000531
Margaret
clojurians
clojure
Yeah, 3) is very problematic. I speak from (painful) experience :slightly_smiling_face:
2017-11-07T17:42:27.000038
Daniell
clojurians
clojure
and yeah, 3 is semi-popular in clojure apps, but also a common source of problems which leads to messy refactors from 3 to 2 or 1
2017-11-07T17:42:44.000106
Margaret
clojurians
clojure
this is part of why people are skeptical of mount btw - it does some of the same things as eg. component or integrant without providing the biggest benefit which is not locking you into singletons, which is a hard thing to fix later if your app design is built around it
2017-11-07T17:43:45.000005
Margaret
clojurians
clojure
Tell me about why all caps is a bad idea
2017-11-07T17:43:58.000606
Sophie
clojurians
clojure
I’ve been using clojure for about 4 years now off and on, but I feel like I still have a lot to learn
2017-11-07T17:44:14.000283
Sophie
clojurians
clojure
it's not a bad idea per se, it's just not conventional
2017-11-07T17:46:09.000340
Kareen
clojurians
clojure
is there some kind of community-approved style guide that I would want to look at?
2017-11-07T17:46:45.000170
Sophie
clojurians
clojure
<https://github.com/bbatsov/clojure-style-guide>
2017-11-07T17:49:16.000070
Kareen
clojurians
clojure
cool, thanks!
2017-11-07T17:56:08.000169
Sophie
clojurians
clojure
Is anyone able to run `lein-marginalia` aka `lein marg` against their codebase using `[org.clojure/clojure "1.9.0-RC1"]` ? The last clojure that `lein marg` seems to work fine with is `[org.clojure/clojure "1.8.0"]` in my codebase.
2017-11-07T17:59:42.000030
Francisca
clojurians
clojure
<@Francisca> I assume you're getting an error? Probably from the spec checking on some macros. Probably Marginalia has illegal `ns` syntax that "just happened" to work on 1.8 and earlier...
2017-11-07T18:37:24.000288
Daniell
clojurians
clojure
Or more likely, some library it depends on, having looked at the source...
2017-11-07T18:38:29.000046
Daniell
clojurians
clojure
clj-uuid states that its squuids `encode retrievably the posix time at which they were generated` anyone know of code to retrieve the posix time? i can figure out the bit math but thought i’d ask first
2017-11-07T18:40:40.000053
Barbera
clojurians
clojure
<@Francisca> I created a new empty Leiningen project, updated Clojure to 1.9.0-RC1 and added `lein-marginalia "0.9.0"` and was able to run it -- but maybe the problem you encountered isn't triggered on an empty project? Can you provide more detail about the problem you are having.
2017-11-07T18:42:18.000063
Daniell
clojurians
clojure
actually nevermind, it’s really simple
2017-11-07T18:44:15.000291
Barbera
clojurians
clojure
<@Daniell> the cause isn't that helpful but I'll post it: ```Exception in thread "main" java.lang.RuntimeException: Problem parsing near line 1 &lt; [taoensso.timbre :refer [info warn error] :as timbre]&gt; original reported cause is java.lang.NoSuchMethodException: clojure.lang.LispReader.matchSymbol(java.lang.Str ing) -- java.lang.NoSuchMethodException: clojure.lang.LispReader.matchSymbol(java.lang.String), compiling:(/tmp/form-init450743688382126384.clj:1:72) ```
2017-11-07T19:14:53.000228
Francisca
clojurians
clojure
looks `ns` related though, what is the issue with illegal `ns` syntax in 1.9?
2017-11-07T19:16:11.000074
Francisca
clojurians
clojure
1.9 checks `ns` syntax more stringently than 1.8 did
2017-11-07T19:19:43.000143
Daniell
clojurians
clojure
that is a reader error, before any macros would see anything
2017-11-07T19:19:44.000384
Rebeca
clojurians
clojure
Yeah, that's what I was thinking having seen the error.
2017-11-07T19:20:06.000373
Daniell
clojurians
clojure
Or maybe an AOT issue?
2017-11-07T19:20:24.000032
Daniell
clojurians
clojure
maybe
2017-11-07T19:20:30.000306
Rebeca
clojurians
clojure
nosuchmethod is rather odd
2017-11-07T19:20:39.000233
Rebeca
clojurians
clojure
yeah, a library aot'ed against a different version of clojure would do it
2017-11-07T19:21:00.000133
Rebeca
clojurians
clojure
<@Francisca> So it's probably specific to your code base setup rather than something in Marginalia per se...
2017-11-07T19:21:37.000098
Daniell
clojurians
clojure
timbre can be really bad for that, because people will write extensions to whatever java logging framework and depend on timbre for whatever reason, but they need to be aot compiled, so you can end up with an aot'ed version of timbre coming in from some other jar
2017-11-07T19:22:28.000002
Rebeca
clojurians
clojure
<https://dev.clojure.org/jira/browse/CLJ-1886?focusedCommentId=42074&amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-42074>
2017-11-07T19:23:39.000104
Rebeca
clojurians
clojure
Repro'd ```Exception in thread "main" java.lang.RuntimeException: Problem parsing near line 1 &lt; [taoensso.timbre :refer [info error warn] :as timbre])&gt; original reported cause is java.lang.NoSuchMethodException: clojure.lang.LispReader.matchSymbol(java.lang.String) -- java.lang.NoSuchMethodException: clojure.lang.LispReader.matchSymbol(java.lang.String), compiling:(/private/var/folders/p1/30gnjddx6p193frh670pl8nh0000gn/T/form-init7849628237322743095.clj:1:125) ```
2017-11-07T19:23:52.000154
Daniell
clojurians
clojure
well, I can change anything. No issue though for lein marg under 1.8.0. I don't even have to use lein marg, but why not?
2017-11-07T19:24:57.000055
Francisca
clojurians
clojure
Marginalia <https://github.com/gdeer81/marginalia/blob/master/src/marginalia/parser.clj#L160>
2017-11-07T19:25:17.000317
Daniell
clojurians
clojure
Calls the LispReader directly -- I suspect the calling arity changed in 1.9?
2017-11-07T19:25:52.000045
Daniell
clojurians
clojure
<https://github.com/gdeer81/marginalia/blob/master/src/marginalia/parser.clj#L117-L120>
2017-11-07T19:26:11.000170
Rebeca
clojurians
clojure
more info here: <https://github.com/gdeer81/marginalia/issues/167>
2017-11-07T19:27:11.000375
Francisca
clojurians
clojure
Ah, there we go. Looks like `matchSymbol` expects two arguments now? A string and a resolver...
2017-11-07T19:28:28.000174
Daniell
clojurians
clojure
1.8 <https://github.com/clojure/clojure/blob/clojure-1.8.0/src/jvm/clojure/lang/LispReader.java#L394> takes just a string
2017-11-07T19:30:32.000135
Daniell
clojurians
clojure
I added a comment to that issue. Maybe <@Herlinda> will be able to chime in?
2017-11-07T19:33:28.000299
Daniell
clojurians
clojure
thank-you, Sean
2017-11-07T19:34:07.000151
Francisca
clojurians
clojure
I wonder if Rich would be ok with clojure 2.0 having breaking changes to remove warts from the core language, or if he wants clojure to be eternally backwards compatible regardless of whether the occasional bad design decision aggregates or not
2017-11-07T20:37:29.000135
Evelin
clojurians
clojure
I mean clojure is a very well designed language but there are a few ugly parts that could use a do-over
2017-11-07T20:38:05.000034
Evelin
clojurians
clojure
i know he mentioned that if he could do it all over again reduce would require an initial value
2017-11-07T20:38:34.000009
Evelin
clojurians
clojure
and rename `for` to something like `sequence-comprehension`
2017-11-07T20:42:28.000029
Margaret
clojurians
clojure
(my suggestion, not anybody elses)
2017-11-07T20:42:37.000197
Margaret
clojurians
clojure
and I tend to think that lazy evaluation of the elements of a sequence and the actual transformation performed over a sequence are orthogonal concepts. its unfortunate that transducers are complected with the idea of immediate evaluation.
2017-11-07T20:43:03.000148
Evelin
clojurians
clojure
are they? you can transduce lazily
2017-11-07T20:43:25.000157
Margaret
clojurians
clojure
(transduce ...) isn't truly lazy
2017-11-07T20:44:12.000151
Evelin
clojurians
clojure
but that’s not the only transducing context - and right, transduce is not lazy
2017-11-07T20:44:29.000041
Margaret
clojurians
clojure
what i'm really getting at is that the core api is more complex than it needs to be simply because it was necessary to keep it backwards compatible and not make a breaking change
2017-11-07T20:45:18.000057
Evelin
clojurians
clojure
what you'd really want to do is be able to define a set of transformations (probably a sequence of transformations actually)
2017-11-07T20:45:53.000270
Evelin
clojurians
clojure
sequence is lazy, and eduction
2017-11-07T20:46:09.000235
Margaret
clojurians
clojure
and defining a transducing function is exactly what you describe
2017-11-07T20:46:34.000187
Margaret
clojurians
clojure
then you'd want to separately define how those transformations are applied to a sequence of data (lazy, not lazy, across multiple cores or not, etc)
2017-11-07T20:47:02.000037
Evelin
clojurians
clojure
transducers are literally a way to define a set of transformations without worrying about representation. the `transduce` function is perhaps a bit misleading as it's a way of applying transducers
2017-11-07T20:47:06.000092
Aldo
clojurians
clojure
right now we have reducers in the core library for handling the parallel case
2017-11-07T20:47:31.000114
Evelin
clojurians
clojure
<@Evelin> you are describing exactly how transducers are used
2017-11-07T20:47:36.000076
Margaret
clojurians
clojure
let me be more specific then
2017-11-07T20:48:06.000223
Evelin