Fork me on GitHub
#code-reviews
<
2017-03-24
>
notanon13:03:42

how do you guys feel about 'pure' functions and annoying signatures?

(defn contains-rc-branch? [^SVNRepository repo ^String path]
  (not= nil (get-directories repo (str path "/branches/RC"))))

(defn contains-trunk-folder? [^SVNRepository repo ^String path]
  (not= nil (get-directories repo (str path "/trunk"))))

(defn get-projects [^SVNRepository repo ^String path]
  (->> (get-all-directories repo path 3)
       (filter (partial contains-rc-branch? repo))
       (filter (partial contains-trunk-folder? repo))))
Passing in the SVN object means every functions need an extra arg and is getting passed around within the ns everywhere. Are free variables within a ns so bad?

hiredman15:03:35

the alternative you are proposing is something like (def repo ...) then leaving it out of all the functions. that is not a good way to write code if you want to test it or reuse it. namespaces are not classes, there is no method to create different "instances" of a namespace with different values for repo

notanon16:03:08

yeah thats pretty much what I thought. I've just been noticing that a lot of my code ends up in anon fns or calls to partial which break the readability and hide the business logic.

notanon16:03:25

especially around filter/reduce/map. which is supposed to be the bread and butter of FP's readability use case

notanon16:03:41

not a big deal i guess, the benefits are worth a little thinking differently

notanon16:03:50

(defn filter-successful-deploy [deploys]
  (filter #(= "SUCCESS" (:deploymentState %)) deploys))

(defn get-environment [{env-name :name
                        id       :id}]
  (-> (call-until-success (str base "deploy/environment/" id "/results") 10)
      :results
      filter-successful-deploy
      first
      (assoc :env-name env-name)))

notanon16:03:40

usually just wrap up the filter with a named fn and suddenly the business intent becomes pretty clear again

notanon16:03:14

although it looks like in that example i should have passed in the base variable instead of relying on it as a constant in my ns

notanon16:03:42

sigh... i feel like OOP has ruined my brain