When I have data relevant to a function that is independent of its arguments, when should I favor block encapsulation over local encapsulation?
When should I use:
(let [hello "Hello "]
(defn do-greet
"Print a greeting."
[name]
(println (str hello name))))
Versus:
(defn do-greet
"Print a greeting."
[name]
(let [hello "Hello "]
(println (str hello name))))
The former is a reasonable option if you want to use the value like a static constant within a lexically scoped block of code. Typically you would do this if:
The latter version should probably be preferred in most other cases, it is good for several reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With