code-reviews

notanon 2017-03-24T13:52:42.406991Z

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?

2017-03-24T15:43:35.869611Z

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

notanon 2017-03-24T16:44:08.202132Z

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.

notanon 2017-03-24T16:45:25.229185Z

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

notanon 2017-03-24T16:48:41.296868Z

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

notanon 2017-03-24T16:48:50.300067Z

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

notanon 2017-03-24T16:49:40.317783Z

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

notanon 2017-03-24T16:57:14.477852Z

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

notanon 2017-03-24T16:57:42.487721Z

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