Fork me on GitHub
#beginners
<
2017-12-30
>
hawari.rahman1704:12:28

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 refactoring.guru, but at this point, I guess any simple article will do 😆

seancorfield06:12:53

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

seancorfield06:12:02

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.

seancorfield06:12:06

Does that help?

hawari.rahman1707:12:47

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))

hawari.rahman1707:12:20

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

hawari.rahman1707:12:37

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.

donaldball15:12:03

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.

hawari.rahman1703:12:11

hi @, 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.

naylyn.gaffney08:12:39

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 https://github.com/weavejester/hiccup but I have no idea if it is a marginal one or not)

hans37812:12:07

there's testing utils in clojure.test

hans37812:12:39

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

sabbatical201713:12:05

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).

sabbatical201713:12:51

I've found something vaguely relevant-looking at https://clojurians-log.clojureverse.org/cider/2017-08-18.html but it's not clear to me what I am supposed to do.

sabbatical201715:12:50

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.

petrus16:12:04

Having a hard time trying to get a free Datomic transactor running on Heroku: https://stackoverflow.com/questions/48035500/heroku-datomic-buildpack-throws-device-eth1-does-not-exist Asked in #datomic but quiet there.

jgh16:12:15

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

hans37816:12:14

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

johnjelinek20:12:20

are there any web development stacks that follow a similar philosophy as this? https://github.com/facebookincubator/create-react-app#philosophy

johnjelinek20:12:19

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

marcjeanson23:12:30

I’m also in the same boat 😞

lee.justin.m00:12:47

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