Is it bad form to stage a function's steps in intermediate variables (let bindings)?
- by octopusgrabbus
I find I tend to need intermediate variables. In Clojure that's in the form of let bindings, like cmp-result-1 and cmp-result-2 in the following function.
(defn str-cmp
"Takes two strings and compares them. Returns the string if a match; and nil if not."
[str-1 str-2 start-pos substr-len]
(let [cmp-result-1 (subs str-1 start-pos substr-len)
cmp-result-2 (subs str-2 start-pos substr-len)]
(compare cmp-result-1 cmp-result-2)))
I could re-write this function without them, but to me, the function's purpose looks clearer. I tend to do this quite in a bit in my main, and that is primarily for debugging purposes, so I can pass a variable to print out intermediate output.
Is this bad form, and, if so, why?
Thanks.