I don't think that it's productive to discuss idiomatic code and performance in 
the same breath.

People do all sorts of nasty stuff when trying to squeeze performance juice out 
of their code. In my experience it's rare to see performance-related "idioms" 
beyond the obvious language-level constructs like type hints and indeed 
loop/recur. When serious performance concerns come into play, idioms are often 
broken via the use of clever tricks.

In the case of loop/recur I think I agree with Tim, Alex, and company.

What you're bringing up is a special case, so to your question I would respond 
with a question: What makes a context-specific performance-related concern 
idiomatic? My guess is very little.

In summary I would say that loop/recur is "idiomatic" when there is a serious, 
verifiable performance concern, but the overarching idiom is to prefer reduce 
as it's more consistent with Clojure's philosophy and design. Loop/recur is 
kind of like swearing. Reduce is typical conversation.  

2c,
--  
{:∂evin :√valters}


On Saturday, May 4, 2013 at 2:43 PM, Cedric Greevey wrote:

> What about the times when one simply must use loop/recur for performance 
> reasons? Although, one thought I had on that was to write a functional 
> version, and if it's a performance bottleneck, write a loop/recur version and 
> call the latter in performance-critical areas, but also have tests that check 
> that both versions have the same semantics.
>  
>  
> On Sat, May 4, 2013 at 1:54 AM, Alex Baranosky <alexander.barano...@gmail.com 
> (mailto:alexander.barano...@gmail.com)> wrote:
> > I concur with Timothy's assessment.  Really well stated and illustrated use 
> > of reduce with a named reduce function.  
> >  
> >  
> > On Fri, May 3, 2013 at 10:52 PM, Timothy Baldridge <tbaldri...@gmail.com 
> > (mailto:tbaldri...@gmail.com)> wrote:
> > > In general, loop/recur shouldn't be considered idiomatic, IMO. Instead, 
> > > try for a more functional style:
> > >  
> > >  
> > > due = 100
> > > cards = cards.map do |card|
> > >     card.applied_balance = max(0, due - card.balance)
> > >     due -= card.applied_balance
> > >  
> > > becomes (untested):
> > >  
> > > (defn apply-balance-1 [{:keys [due] :as accum} [card-id balance]]
> > >   (let [applied (max (- due balance))]
> > >     (-> accum  
> > >          (assoc-in [:applied card-id] applied)
> > >          (assoc-in [:due] due))))
> > >  
> > >  
> > > (reduce apply-balance-1
> > >             {:due 100}
> > >             {:card-id-1 4404.00
> > >              :card-id-2 3020.00
> > >              ....etc....})
> > >  
> > > Often I have found that using reduce forces me to break functions into 
> > > several parts. If I used loop/recur, normally the function prelude, 
> > > postlude and loop block are all smashed into a single function. With 
> > > reduce + a do-step-1 function (as seen above) we can more easily reason 
> > > about what is happening. The code is then easier to test as well, as we 
> > > can test the calculations apart from the loop logic.  
> > >  
> > > When I'm performing Clojure code reviews, I often consider loop/recur to 
> > > be a code smell.  
> > >  
> > > Timothy
> > >           
> > >  
> > >  
> > >  
> > > On Fri, May 3, 2013 at 3:53 PM, Armando Blancas <abm221...@gmail.com 
> > > (mailto:abm221...@gmail.com)> wrote:
> > > > On Friday, May 3, 2013 1:15:24 PM UTC-7, Robert Pitts wrote:
> > > > > Armando was a good citizen and sent along a plain-text version as 
> > > > > well – 
> > > > > https://groups.google.com/group/clojure/msg/6aae8287bc55d436?dmode=source&output=gplain&noredirect
> > > >  
> > > >  
> > > > That must have been Google Groups doing the right thing... nice feature.
> > > >  
> > > > --  
> > > > --  
> > > > 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 
> > > > (mailto: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 
> > > > (mailto:clojure%2bunsubscr...@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 
> > > > (mailto:clojure%2bunsubscr...@googlegroups.com).
> > > > For more options, visit https://groups.google.com/groups/opt_out.
> > > >   
> > > >   
> > >  
> > >  
> > >  
> > > --  
> > > “One of the main causes of the fall of the Roman Empire was that–lacking 
> > > zero–they had no way to indicate successful termination of their C 
> > > programs.”
> > > (Robert Firth)  
> > >  
> > > --  
> > > --  
> > > 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 
> > > (mailto: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 
> > > (mailto:clojure%2bunsubscr...@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 
> > > (mailto:clojure%2bunsubscr...@googlegroups.com).
> > > For more options, visit https://groups.google.com/groups/opt_out.
> > >   
> > >   
> >  
> > --  
> > --  
> > 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 
> > (mailto: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 
> > (mailto:clojure%2bunsubscr...@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 
> > (mailto:clojure%2bunsubscr...@googlegroups.com).
> > For more options, visit https://groups.google.com/groups/opt_out.
> >   
> >   
>  
> --  
> --  
> 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 
> (mailto: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 
> (mailto: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 
> (mailto:clojure+unsubscr...@googlegroups.com).
> For more options, visit https://groups.google.com/groups/opt_out.
>   
>   

-- 
-- 
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/groups/opt_out.


Reply via email to