Fork me on GitHub
#clojure-europe
<
2021-02-19
>
javahippie07:02:24

Good Morning!

slipset08:02:34

An interesting effect of clojure-lsp and lenses is that I’m made aware of fns which only are used once. I find that a bunch of them are quite useless and an indication of something to be fixed.

👍 4
reefersleep08:02:55

Indeed! Helper functions can be nice, but are often superfluous, I find - and can be inlined.

otfrom08:02:47

the upside is one less thing to name and the downside being that your function is longer and lacking in a meaningful name?

slipset09:02:16

There are some other upsides, but I haven’t quite been able to formulate it. Sometimes it’s a too specialized fn, ie something like:

(defn find-by-name [db name]
  (query! db {:name name}))

otfrom09:02:37

fair enough. Depends on the length of the helper I suppose

reefersleep09:02:00

Exactly, @U0525KG62. I loved making helper functions when I first started learning Clojure, but now that I’m more comfortable with the core, I prefer a larger function body than loads of names for arbitrary bits of code - it’s harder to come up with them, and it’s harder to read (remember) them. Generality of the helper functions, like I believe @U04V5VAUN is talking about, also weighs in on the matter. I feel like the more your helper functions feel like an extension of the Clojure core in terms of naming and behaviour (like nil punning), the better. It’s never black and white, of course 🙂

👍 4
slipset10:02:40

Also, our fns which look like the above have had a tendency to be like:

(defn find-by-lots-of-things [db foo bar baz qix and some other stuff]
  (query db ...lots of calculations to make the query)) 
Which then (IMO) is better done as:
(defn query-for-lots-of-things [foo bar baz qix and some other stuff]
  ...lots of calculations to make the query)
The upside to this is that suddenly you (if you use honesql or some other data based query language) have composable things which lets you write:
(->> (query-for-lots-of-things foo bar baz qix and some other stuff)
     (merge (by-id id)
     (query! db)

👍 8
reefersleep11:02:21

Always Be Composing 🙂

reefersleep11:02:09

That’s a good rule in general, I think. Leave the composition to the caller.

reefersleep11:02:29

Insofar as possible.

dharrigan08:02:42

Good Morning!

pez16:02:45

Morning folks! I posted this in #babashka, but think it fits here as well. I often search for “clojure” on Youtube, filtering on newest first. Today I tried another filter. It’s that dude we all admire and love. 😃 ❤️

babashka 24