Hello, I fear there isn't (at least for me) a simple general answer for such a general problem, because :
* it will really depend on the context : are op1 and op2 themselves cryptic names that would benefit from having their result clearly named ? are op1 and op2 "low level operations" for which a more "abstract" name given in the let could help the rest of the let body be itself more abstract too ? * it is possible to abuse both forms if you replace a careful thought of the pros and cons with a "global rule" which, while certainly written with the best intent in mind, endlessly becomes eventually followed blindly by some (if not most) people. I prefer being more general and keep in mind these guideline (and they really are just guidelines) "rules" : - the code should be clear and reveal the intent (but it should not consider readers are newbies that don't know the language idioms) - the code should have no repetition So more or less 2 of the XP rules ... (don't remember the other ones right now, but they are interesting, too) 2009/2/25 levand <luke.vanderh...@gmail.com> > > 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 -~----------~----~----~----~------~----~------~--~---