Of course,  the use of let does not make the code any more imperative or
less functional, as long as there are no side effects. Also, the scope is
limited to the let  block, keeping it "clean," and there should be no harm
to performance.
IMHO, the code with let is simply more readable and therefore more elegant.

Joshua

On Wed, Feb 25, 2009 at 10:57 PM, levand <luke.vanderh...@gmail.com> wrote:

>
> Recently, in my code, I have been struggling with which of the two
> equivalent forms is, in a general sense, "better".
>
> (defn my-fn1 [input]
>  (let [value1 (op1 input)
>        value2 (op2 input)
>        value3 (op4 value1 value2)]
>    (op5 value3)))
>
> (defn my-fn2 [input]
>  (op5 (op4 (op1 input) (op2 input))))
>
> Now, the second is definitely cleaner and more elegant, besides being
> smaller, which is a non-trivial benefit when I have a fair amount of
> code to page through.
>
> However, if I've been away from the code awhile, it's much easier to
> come back determine what the code is doing when its written the first
> way, especially when it uses descriptive names. An operation that is
> impenetrable when written in nested form can become quite simple when
> each step is broken down and labeled.
>
> Clojure is my first Lisp - should I just stick with the second form
> until I learn to "see through" the nested s-expressions?
>
> It's not that I'm trying to make my code more imperative - Although I
> come from a Java background, I love functional programming, and it is
> a delight to see how much I can do without side-effects. But I do miss
> the self-documentation that well-named variables can provide.
>
> Any thoughts? Also, is there any performance degradation from the
> first way, or can the compiler optimize it away?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to