On Sunday, October 30, 2016 at 10:50:08 PM UTC-4, Mikera wrote:
>
>
> I actually prefer the following style to both of the above:
>
> (defn camel->keyword*
>          [s]
>          (let [words (str/split s #"(?<=[a-z])(?=[A-Z])")
>                lc-words (map str/lower-case words)
>                joined-words (str/join "-" lc-words)]
>            (keyword joined-words))) 
>
> Reasons:
> - Your intermediate values are explicitly named, which helps to make the 
> code self-describing
> - It is (marginally) more performant than the composed function case (I 
> think exactly matches the threading macro)
> - You can use the intermediate values in more than one of the following 
> steps if needed, which can make refactoring / adding new features easier
> - The ordering is (to me) more logical as it describes the stages of the 
> transformation in the order they are performed.
> - It is less "Clever". Clever code is generally bad for maintenance and 
> future understanding. Both functional composition and the 
> code-transformation effects of the threading macro represent conceptual 
> overhead that you don't need to pay (in this case).
>

 Wow! I much prefer this style. I'm impressed that even though it's clearer 
(to me), it doesn't suffer in performance.

Thanks for not only showing a clearer way to do this, but also outlining 
good arguments for why one might want to.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to