Fork me on GitHub

does anybody know resource/article/guide that can explain refactoring strategy in clojure (or LISP in general), I've been struggling on how to deal with impure functions, mostly because of their testability. I was hoping something like, but at this point, I guess any simple article will do 😆


@hawari.rahman17 Can you be a bit more specific about what you're struggling with? Is this database code or something else?


Impure functions are not necessarily "bad" but they can always be refactored into a pure function that returns a data structure representing a delta on the environment and an impure function that accepts that data structure and performs the actual update. You still have the task of testing the update functions but that's a more focused task -- and then your pure functions can often be tested generatively.


Does that help?


hi @seancorfield, mostly it's when I'm dealing with database calls, I have a tasks that kinda looks like this:

(defn do-tasks [args]
  (do-some-validation args)
  (store args))


I think we already have this kind of conversation, haven't we? the solution that I came up with is to "inject" the store function into do-tasks


but now I'm saying that I need some kind of reference is because I sense that a lot of my code smells, not just necessarily because impure functions. I sort of need a pointer on what's next to learn for a clojure programmer, like learning design patterns next if you're already comfortable with OOP concept.


I think there are a couple of things you could try. One would be something like Sean described above: have your do-tasks fn return a data structure specifying the actions the impure fn is going to perform. This is very easy and nice in e.g. datomic, but can also apply to sql using e.g. honeysql or the like. Another would be to define a protocol for your impure thing. For a database in particular, one is advised to not try to define a protocol for arbitrary database interactions, that’s just too complex and doesn’t buy you anything. Define a protocol for the things your caller needs and implement those. (I think one fairly quickly develops an aesthetic judgment on when the protocol is coherent or not, but you’ll make mistakes at first. No worries!) Then, pass an impl of the protocol into all the formerly impure fns. Note these techniques aren’t exclusive, but can complement each other.


hi @U04V4HWQ4, thank you for the advice. I guess the thing that keeps me struggling even after months of experimenting with clojure is I tend to revisit the things that I've done in my previous languages: mocking, injecting dependency, and I always try to find the equivalent in clojure. that's why I'm kind of looking for something to refresh my understanding of clojure: why things the way it is, what to avoid and what to look for when building something.


Does anyone have experience working with quil? I'm hoping for some tips on workflows and dealing with errors in draw functions.

Vincent Cantin11:12:49

Hello, I am a beginner in the closure eco-system. I have some questions I would like to ask ..

Vincent Cantin11:12:19

1. are there some testing library which have the concept of 'compare to snapshots', similar to jest ()?

Vincent Cantin11:12:10

2. Which libraries are commonly used for generating html? (I found but I have no idea if it is a marginal one or not)


there's testing utils in clojure.test


@vincent.cantin and hiccup doesn't look too marginal to me, judging from its github stars / watchers


I have a Clojure app that interacts with other commands through its stdin and stdout. I have been able to run an nrepl server from my app and interact with it from Cursive while it is running. It's fun! However, when I try to do the same from CIDER, it does not work. I am able to connect to my nrepl server with cider-connect and am able to evaluate forms. However, it seems that CIDER captures stdout from my app and makes it go into my Emacs instead of where it is supposed to go (through the original stdout to another app that I am supposed to be interacting with).


I've found something vaguely relevant-looking at but it's not clear to me what I am supposed to do.


For those of you who are also interested in the answer to my question two and a half hours ago, I have a solution. Instead of using :handler cider-nrepl-handler in my starting the nrepl server, I created a custom my-cider-nrepl-handler, which is the same as cider.nrepl/cider-nrepl-handler, except that it uses a custom version of the cider-middleware vector which omits the wrap-out entry.

Petrus Theron16:12:04

Having a hard time trying to get a free Datomic transactor running on Heroku: Asked in #datomic but quiet there.


i guess trying to figure out how to get your onto heroku is probably the place to start


i think that's only possible with at least an evaluation license


are there any web development stacks that follow a similar philosophy as this?


I'm having analysis paralysis at all the micro libraries available to set up a figwheel + react environment


I’m also in the same boat 😞


Me too. I know that someone is working on it. For the time being I liked the tenzing templates