﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Apalmer commented on Sometimes imperative is so much easier</title><description>Doesnt look idiomatic functional programming at all, it looks like a mechanical conversion of an imperative loop with mutating state to a recursive function call with accumulators. Which is basic functional programming 101, but in general once the user learns that they can do this relieably, they then move on to composing simple functions over lists to accomplish the same goal. Not sure its possible that maybe there is some performance gain in the erlang implementation if you feel this was programmed by advanced functional programmers. A lot of times when performance is taken into account, an advanced programmer has to strip out all the nice functional patterns and put in some worst of both worlds imperative/functional chimera
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment11</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment11</guid><pubDate>Wed, 12 May 2010 14:50:45 GMT</pubDate></item><item><title>Igor K. commented on Sometimes imperative is so much easier</title><description>count_promises(Id, N, {_, PromisesQueue}) -&gt;
  
  length(lists:filter(fun(X, Y, _, _}) -&gt; X =:= Id andalso Y =:= N end, PromisesQueue)).
  
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment10</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment10</guid><pubDate>Tue, 11 May 2010 21:15:24 GMT</pubDate></item><item><title>NoComments commented on Sometimes imperative is so much easier</title><description>Probably no comments in the mess either.
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment9</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment9</guid><pubDate>Tue, 11 May 2010 21:02:14 GMT</pubDate></item><item><title>Bobo commented on Sometimes imperative is so much easier</title><description>count_promises(Id, N, {_, PromisesQueue}) -&gt; 
  
  lists:foldr(fun(X,ACC) -&gt; {I,NN,_,_} = X, if I==Id , NN==N -&gt;  ACC+1; true -&gt;  ACC end  end , 0, PromisesQueue).
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment8</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment8</guid><pubDate>Tue, 11 May 2010 14:05:03 GMT</pubDate></item><item><title>configurator commented on Sometimes imperative is so much easier</title><description>Oh. I thought you said "idiotic" Erlang code.
  
I think yes, it is.
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment7</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment7</guid><pubDate>Tue, 11 May 2010 13:29:14 GMT</pubDate></item><item><title>tobi commented on Sometimes imperative is so much easier</title><description>This cannot be idiomatic erlang code because it would mean that most erlang programmers are not very smart. That is hard to believe.
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment6</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment6</guid><pubDate>Tue, 11 May 2010 12:07:11 GMT</pubDate></item><item><title>Max commented on Sometimes imperative is so much easier</title><description>This is horrible functional programming style. I'm not a Erlang wizard, so this is how I would write the function in Haskell:
  
  
countPromises id n = length . filter (\(id', n') -&gt; id' == id &amp;&amp; n' == n) . snd
  
  
Much better! If you want it to look like C# you can also define:
  
  
count p = length . filter p
  
countPromises id n = count (\(id', n') -&gt; id' == id &amp;&amp; n' == n) . snd
  
  
If you use GHC, all the intermediate lists wil be fused away, so this will actually compile into the tight imperative loop you wrote above.
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment5</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment5</guid><pubDate>Tue, 11 May 2010 11:25:29 GMT</pubDate></item><item><title>Demis Bellot commented on Sometimes imperative is so much easier</title><description>Yeah it's hard to see how this can can be more readable in anyone's mind. I'm aware the mathematical mind works differently and prefers the purity of functional programming without side-effects but does it work this different?
  
  
IMHO readability of code is just as important as succinctness, i.e. there's no point having really tight code with low signal/noise ratio if it takes others longer to scan and understand a page of code.
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment4</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment4</guid><pubDate>Tue, 11 May 2010 10:18:18 GMT</pubDate></item><item><title>Ayende Rahien commented on Sometimes imperative is so much easier</title><description>Paul,
  
No, libpaxos
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment3</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment3</guid><pubDate>Tue, 11 May 2010 09:48:17 GMT</pubDate></item><item><title>Andrew Davey commented on Sometimes imperative is so much easier</title><description>Writing out the recursion and pattern matching for this function sure feels like a waste of time.
  
  
It seems to me that the Erlang code should be re-factored to make use of higher level functions, like "filter".
  
  
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment2</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment2</guid><pubDate>Tue, 11 May 2010 09:35:03 GMT</pubDate></item><item><title>Paul Cowan commented on Sometimes imperative is so much easier</title><description>Did the Erlang code come from couchdb?
  
  
If so, I would be curious to know what benefit there is in rewriting couchdb on another platform?
  
  
</description><link>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment1</link><guid>http://ayende.com/4495/sometimes-imperative-is-so-much-easier#comment1</guid><pubDate>Tue, 11 May 2010 09:21:55 GMT</pubDate></item></channel></rss>