<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Erlang: Pattern Matching Declarations vs Case Statements/Other</title>
	<atom:link href="http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/</link>
	<description></description>
	<lastBuildDate>Sun, 01 Apr 2012 20:37:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: John Bender</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-2882</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Thu, 14 May 2009 13:02:58 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-2882</guid>
		<description>@Ravindranath

I imagine it compiles down to something similar either way, but its good to know you don&#039;t have to take a performance hit.</description>
		<content:encoded><![CDATA[<p>@Ravindranath</p>
<p>I imagine it compiles down to something similar either way, but its good to know you don&#8217;t have to take a performance hit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravindranath Akila</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-2878</link>
		<dc:creator>Ravindranath Akila</dc:creator>
		<pubDate>Thu, 14 May 2009 10:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-2878</guid>
		<description>-module(speed).
-export([run/1,loop_case/1,loop_fun/1,is_even/1,fun_it/2]).

run(N)-&gt;
    error_logger:info_report(timer:tc(?MODULE,loop_fun,[N])),
    error_logger:info_report(timer:tc(?MODULE,loop_case,[N])).
    
    
is_even(I)-&gt;
    I rem 2 == 0.
    
loop_case(0)-&gt;
    finish;
loop_case(N)-&gt;
    case_it(N,is_even(N)).

case_it(N,Boolean)-&gt;
    case Boolean of
        true-&gt;
            loop_case(N-1);
        false-&gt;
            loop_case(N-1)
    end.

loop_fun(0)-&gt;
    finish;
loop_fun(N)-&gt;
    fun_it(N,is_even(N)).


fun_it(N,true)-&gt;
    loop_fun(N-1);
fun_it(N,false)-&gt;
    loop_fun(N-1).



Results

36&gt; speed:run(10000000).

=INFO REPORT==== 14-May-2009::15:51:36 ===
{1484000,finish}
ok

=INFO REPORT==== 14-May-2009::15:51:38 ===
{1390999,finish}
37&gt;

Seems like no difference:)</description>
		<content:encoded><![CDATA[<p>-module(speed).<br />
-export([run/1,loop_case/1,loop_fun/1,is_even/1,fun_it/2]).</p>
<p>run(N)-&gt;<br />
    error_logger:info_report(timer:tc(?MODULE,loop_fun,[N])),<br />
    error_logger:info_report(timer:tc(?MODULE,loop_case,[N])).</p>
<p>is_even(I)-&gt;<br />
    I rem 2 == 0.</p>
<p>loop_case(0)-&gt;<br />
    finish;<br />
loop_case(N)-&gt;<br />
    case_it(N,is_even(N)).</p>
<p>case_it(N,Boolean)-&gt;<br />
    case Boolean of<br />
        true-&gt;<br />
            loop_case(N-1);<br />
        false-&gt;<br />
            loop_case(N-1)<br />
    end.</p>
<p>loop_fun(0)-&gt;<br />
    finish;<br />
loop_fun(N)-&gt;<br />
    fun_it(N,is_even(N)).</p>
<p>fun_it(N,true)-&gt;<br />
    loop_fun(N-1);<br />
fun_it(N,false)-&gt;<br />
    loop_fun(N-1).</p>
<p>Results</p>
<p>36&gt; speed:run(10000000).</p>
<p>=INFO REPORT==== 14-May-2009::15:51:36 ===<br />
{1484000,finish}<br />
ok</p>
<p>=INFO REPORT==== 14-May-2009::15:51:38 ===<br />
{1390999,finish}<br />
37&gt;</p>
<p>Seems like no difference:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bender</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-1212</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Mon, 23 Mar 2009 19:22:57 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-1212</guid>
		<description>@Mason

Agreed, I think if/case statements are soft of an afterthought for erlang, which is fine with me. I think R. Virding wrote something like this on his blog.</description>
		<content:encoded><![CDATA[<p>@Mason</p>
<p>Agreed, I think if/case statements are soft of an afterthought for erlang, which is fine with me. I think R. Virding wrote something like this on his blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mason</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-1211</link>
		<dc:creator>Mason</dc:creator>
		<pubDate>Mon, 23 Mar 2009 19:04:07 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-1211</guid>
		<description>I don&#039;t know what the overhead of pattern matching on a function versus in a case statement are, but I&#039;m pretty sure the &quot;Erlang Way&quot; is the one that avoids a lot of if/else-type statements in favor of pattern-matched tail recursion, as you&#039;ve written it. I also think it reads much more naturally:

operation(Thing) -&gt;
 % something funky which binds Result
 Result.

something([], Accum) -&gt;
 Accum;

something([Next &#124; Rest], Accum) -&gt;
 something(Rest, operation(Next)). 

To me, that reads: `something` will return Accum if the first parameter is an empty list, `something` will operate and recurse if there&#039;s an element to be used.  I can read the purpose of the function by reading its definition, instead of delving into its guts.

Kudos.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know what the overhead of pattern matching on a function versus in a case statement are, but I&#8217;m pretty sure the &#8220;Erlang Way&#8221; is the one that avoids a lot of if/else-type statements in favor of pattern-matched tail recursion, as you&#8217;ve written it. I also think it reads much more naturally:</p>
<p>operation(Thing) -&gt;<br />
 % something funky which binds Result<br />
 Result.</p>
<p>something([], Accum) -&gt;<br />
 Accum;</p>
<p>something([Next | Rest], Accum) -&gt;<br />
 something(Rest, operation(Next)). </p>
<p>To me, that reads: `something` will return Accum if the first parameter is an empty list, `something` will operate and recurse if there&#8217;s an element to be used.  I can read the purpose of the function by reading its definition, instead of delving into its guts.</p>
<p>Kudos.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmkogut</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-128</link>
		<dc:creator>jmkogut</dc:creator>
		<pubDate>Tue, 20 Jan 2009 00:29:12 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-128</guid>
		<description>Kindof! Refactoring is fun.</description>
		<content:encoded><![CDATA[<p>Kindof! Refactoring is fun.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bender</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-127</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Mon, 19 Jan 2009 20:42:17 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-127</guid>
		<description>@jmkogut

The more I look at it the more I&#039;m starting to agree with you. Personal preference to a point I guess.

I should probably finish the software before bothering with stuff like this though eh?</description>
		<content:encoded><![CDATA[<p>@jmkogut</p>
<p>The more I look at it the more I&#8217;m starting to agree with you. Personal preference to a point I guess.</p>
<p>I should probably finish the software before bothering with stuff like this though eh?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmkogut</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-125</link>
		<dc:creator>jmkogut</dc:creator>
		<pubDate>Mon, 19 Jan 2009 16:01:59 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-125</guid>
		<description>Also: http://gist.github.com/49033

That additional formatting is all I can think of to make it easier to read. A quick glance at that function is easier to understand than tracing through head matching functions, imho.</description>
		<content:encoded><![CDATA[<p>Also: <a href="http://gist.github.com/49033" rel="nofollow">http://gist.github.com/49033</a></p>
<p>That additional formatting is all I can think of to make it easier to read. A quick glance at that function is easier to understand than tracing through head matching functions, imho.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmkogut</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-124</link>
		<dc:creator>jmkogut</dc:creator>
		<pubDate>Mon, 19 Jan 2009 15:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-124</guid>
		<description>I&#039;ve always found cases to be pretty elegant. It&#039;s the if statements that irk me.

but as you said, the case is less syntax. If you can do the same function, with less to type, and without losing clarity, go for it.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve always found cases to be pretty elegant. It&#8217;s the if statements that irk me.</p>
<p>but as you said, the case is less syntax. If you can do the same function, with less to type, and without losing clarity, go for it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bender</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-122</link>
		<dc:creator>John Bender</dc:creator>
		<pubDate>Sun, 18 Jan 2009 18:26:59 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-122</guid>
		<description>@jmkogut

It might be less syntax for the case statement, but I think Erlangs case/if statements are sort of clunky. That&#039;s the only reason I can come up with for why I like using the head matching.</description>
		<content:encoded><![CDATA[<p>@jmkogut</p>
<p>It might be less syntax for the case statement, but I think Erlangs case/if statements are sort of clunky. That&#8217;s the only reason I can come up with for why I like using the head matching.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmkogut</title>
		<link>http://johnbender.us/2009/01/17/erlang-pattern-matching-declarations-vs-case-statementsother/comment-page-1/#comment-121</link>
		<dc:creator>jmkogut</dc:creator>
		<pubDate>Sun, 18 Jan 2009 18:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://nickelcode.com/?p=42#comment-121</guid>
		<description>I&#039;m voting for the case statement just because it seems more elegant. I&#039;m not sure about speed though. You might want to profile both methods and see what results you get.</description>
		<content:encoded><![CDATA[<p>I&#8217;m voting for the case statement just because it seems more elegant. I&#8217;m not sure about speed though. You might want to profile both methods and see what results you get.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

