Good Morning!
Good morning!
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.
Indeed! Helper functions can be nice, but are often superfluous, I find - and can be inlined.
Good Morning!
👋
the upside is one less thing to name and the downside being that your function is longer and lacking in a meaningful name?
morning
:morning:
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}))
fair enough. Depends on the length of the helper I suppose
morning
Exactly, @otfrom. 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 @slipset 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 🙂
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)
Morning
Morning
Always Be Composing 🙂
That’s a good rule in general, I think. Leave the composition to the caller.
Insofar as possible.
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. 😃 ❤️