off-topic

https://github.com/clojurians/community-development/blob/master/Code-of-Conduct.md Clojurians Slack Community Code of Conduct. Searchable message archives are at https://clojurians-log.clojureverse.org/
clyfe 2021-01-18T08:38:36.174600Z

There are a lot of .thing configs piling up in a project root; the convention .config/thing would be better (if all would follow it, not some).

2021-01-18T08:42:36.174700Z

If you mean in general for all software, that’s a big ask. Some use such dotfiles to discover project root as well

clyfe 2021-01-18T09:01:37.174900Z

In linux ~/.config dir became more established in recent times. Good point on discovery; but I'd guess if the folder is hidden (starts with ".") is less relevant to such use (at least compared to, say, deps.edn).

clyfe 2021-01-18T09:02:41.175100Z

Also, on discovery & such, .config/thing can still act as an indicator

2021-01-18T09:05:13.175300Z

it would definitely be cleanlier

2021-01-18T09:07:30.175500Z

I guess if you have strong feelings about it, you must create a blog-post and get hype on hackernews and similar for people to start adopting the convention

sP0re 2021-01-18T10:27:19.183200Z

Hi, I have a question that is not related to Clojure but more to functional programming in general. How can you make dependency injection? And If you have 2 modules, how will you make the first one to use the second one with dependency inversion? I haven’t covered this topic with clojure yet (I’m studying the basics) but I’m sperimenting something with Spring and Java Reactor with Functional interfaces. In a OO world I usually inject an interface in module 1 (defining a Bean that returns an instance of Module 2) and then I implement that in the module 2. I cannot use Suppliers, Functions and Bifunctions instead regular methods in this way in Java. I can’t use the interface. So What is the right approach based on your experience with func programming in general? Thank you a lot

rakyi 2021-01-18T10:43:53.184300Z

in general, pass function as a parameter 🙂 this might give you some ideas, if you are new to FP http://mishadoff.com/blog/clojure-design-patterns/

rakyi 2021-01-18T10:44:52.184500Z

if you need to manage stateful things look at https://github.com/stuartsierra/component (and its alternatives)

sP0re 2021-01-18T11:16:33.185Z

Ok, but if I don’t want module 1 knowing module 2, if I pass a function as parameter it has to know that module, or not?

sP0re 2021-01-18T11:17:07.185200Z

I’ll look for clojure design patterns, thanks :)

simongray 2021-01-18T12:46:20.185900Z

@mircoporetti You can pass a function or a piece of mutable state or whatever you need. Your modules don’t have to “know” each other. They just assume that the passed in arg is e.g. a function and therefore call it as a function. In OOP you typically bundle functions and state as an object. In Clojure, you might simply use a map or a record instead of an object if you need to conform to some kind of complex interface. Clojure Spec (or malli or schema) can be used to describe the shape of the data if you also need to validate it.

sP0re 2021-01-18T12:50:03.186300Z

Interesting!

simongray 2021-01-18T12:53:33.186700Z

A lot of Clojure-style functional programming is enabled by decomposing what you are used to with objects into data (mutable and immutable) and functions operating on the data (side-effecting and pure). It is much more useful to have this separation.

simongray 2021-01-18T12:56:48.186900Z

So the pure functions operate on immutable data, while side-effecting functions (often marked with a !) operate on your mutable state. You generally want to expose the smallest possible surface area of your data as mutable state. Less mutable state leads to fewer side-effecting functions.

👍 2
emccue 2021-01-18T13:12:56.188Z

@mircoporetti Maybe this code example will make sense

emccue 2021-01-18T13:13:30.188800Z

(ns user.persit
  (:require [next.jdbc :as jdbc]))

(defn for-id [db id]
  (jdbc/select "users" {:id id}))

emccue 2021-01-18T13:14:36.189500Z

first, you have functions that take what they want explicitly as parameters

emccue 2021-01-18T13:14:40.189700Z

then

emccue 2021-01-18T13:15:11.190400Z

(defn create-system []
  {:db (connect-to-database)
   :redis (connect-to-redis)})

emccue 2021-01-18T13:15:33.190900Z

you have some procedure that returns a map of all the stateful "system like" stuff in your app

emccue 2021-01-18T13:15:52.191400Z

(there are a few approaches to this, but for now just imagine you do it manually in one place)

emccue 2021-01-18T13:16:18.191900Z

then at the service level you have functions that take this map

emccue 2021-01-18T13:17:09.192900Z

(possibly wrapped in some context for stuff like http)

emccue 2021-01-18T13:18:46.194800Z

(defn figure-out-first-user [request]
  (let [{:keys [db]]      (:context request)
        {:keys [user-id]} (:json-params request)]
    (p-user/for-id db user-id)))

emccue 2021-01-18T13:19:10.195400Z

and functions at the top level take out the parts of the system that they care about

emccue 2021-01-18T13:19:18.195600Z

"declare their dependencies"

emccue 2021-01-18T13:19:43.196100Z

the wiring changes depending on how you structure your app, but thats the gist of it

emccue 2021-01-18T13:20:06.196500Z

"look for the keys in a map that you care about"

emccue 2021-01-18T13:35:54.196900Z

That is the clojure specific answer

emccue 2021-01-18T13:37:19.198400Z

As far as statically typed functional languages go,

emccue 2021-01-18T13:37:49.198900Z

Scala uses "implicit parameters" for DI

emccue 2021-01-18T13:38:18.199600Z

Haskell uses the power of imagination and something something partial function application

2021-01-18T15:16:07.202800Z

looking at this john hopkins map of the US coronavirus infctions. How come the big around the middle west ish seems to have got away with relatively few infections? Is this infections map starting to be like a representation of population density? (I'm not from the US) Is the east coast and eastern middle far more densly populated, or something going on?

2021-01-18T15:17:29.203500Z

are people in the west of the country generally more careful or maybe those states tend to have tighter controls?

2021-01-18T15:20:51.204400Z

Yeah, it’s looking a lot like a population density map lately. The Plains states are generally more sparsely populated.

2021-01-18T15:21:17.205Z

That map looks a lot like a population density map of the USA. There are very few people living in the Rocky mountains compared to the west coast

2021-01-18T15:44:13.205900Z

https://xkcd.com/1138/

2021-01-18T16:27:23.206700Z

Depending upon what kind of info you are looking for, a map that showed different colors for percentages of local population with some property you are interested, might be more useful.

emccue 2021-01-18T16:36:24.207200Z

@qmstuart There are honestly too many conflating factors in infection data

emccue 2021-01-18T16:36:49.207800Z

a lot of states artificially make getting tests hard for either everyone or just certain populations

emccue 2021-01-18T16:37:17.208500Z

and looking at absolute numbers won't tell you much specifically because its just a population density map at a certain point

emccue 2021-01-18T16:38:06.208900Z

covid deaths per capita by state might be more useful

emccue 2021-01-18T16:38:28.209700Z

but even that is somewhat inaccurate and won't tell you much without more specific time slices

emccue 2021-01-18T16:49:05.210400Z

the most accurate data will be excess deaths

emccue 2021-01-18T16:49:42.211100Z

or if your locale has something similar to this

emccue 2021-01-18T16:49:43.211300Z

https://www.mwra.com/biobot/biobotdata.htm

emccue 2021-01-18T16:50:15.212Z

which can work as a proxy for testing for determining the relative magnitude of community spread

emccue 2021-01-18T16:50:29.212300Z

since everyone poops

seancorfield 2021-01-18T19:43:26.222900Z

Folks, we have a #covid-19 channel where aspects of that can be discussed. We'd rather folks "opted in" to that discussion rather than have it in a big channel like this.

👍 4
🙏 2
1