<?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: Functional is not Procedural</title>
	<atom:link href="http://thesmithfam.org/blog/2010/01/05/functional-is-not-procedural/feed/" rel="self" type="application/rss+xml" />
	<link>http://thesmithfam.org/blog/2010/01/05/functional-is-not-procedural/</link>
	<description>Your blog is probably better than mine.</description>
	<lastBuildDate>Sun, 05 Feb 2012 05:18:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Evan Farrer</title>
		<link>http://thesmithfam.org/blog/2010/01/05/functional-is-not-procedural/comment-page-1/#comment-96971</link>
		<dc:creator>Evan Farrer</dc:creator>
		<pubDate>Wed, 06 Jan 2010 04:04:28 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=562#comment-96971</guid>
		<description>I think the difference is easier to understand by looking at code written in the different styles.  Here is an implementation of factorial written in a procedural style:

int procedural_factorial(int n)
{
    int fact = 1;
    while (n &gt; 1)
    {
        fact *= n;
        n--;
    }

    return fact;
}

Here is another implementation of factorial written in a functional style:

int functional_factorial(const int n)
{
    if (n &lt;= 1)
    {
        return 1;
    }
    else
    {
        return n * functional_factorial(n-1);
    }
}

Notice that the in the functional style the value of a variable is *never*  mutated.  In functional programming you don&#039;t mutate variables (all variables could be declared as constants) you just create new variables with new values.  Also notice that the functional style uses recursion.  Recursion is scary for C/C++ programmers because you&#039;re always worried about blowing your stack, in functional programming languages you can write recursive functions that don&#039;t grow the stack.  At first glance it seems impossible to write any &quot;real&quot; programs if you&#039;re not allowed to mutate variables, but you can.  You just have to develop a new way of thinking and solving problems.</description>
		<content:encoded><![CDATA[<p>I think the difference is easier to understand by looking at code written in the different styles.  Here is an implementation of factorial written in a procedural style:</p>
<p>int procedural_factorial(int n)<br />
{<br />
    int fact = 1;<br />
    while (n &gt; 1)<br />
    {<br />
        fact *= n;<br />
        n&#8211;;<br />
    }</p>
<p>    return fact;<br />
}</p>
<p>Here is another implementation of factorial written in a functional style:</p>
<p>int functional_factorial(const int n)<br />
{<br />
    if (n &lt;= 1)<br />
    {<br />
        return 1;<br />
    }<br />
    else<br />
    {<br />
        return n * functional_factorial(n-1);<br />
    }<br />
}</p>
<p>Notice that the in the functional style the value of a variable is *never*  mutated.  In functional programming you don&#039;t mutate variables (all variables could be declared as constants) you just create new variables with new values.  Also notice that the functional style uses recursion.  Recursion is scary for C/C++ programmers because you&#039;re always worried about blowing your stack, in functional programming languages you can write recursive functions that don&#039;t grow the stack.  At first glance it seems impossible to write any &quot;real&quot; programs if you&#039;re not allowed to mutate variables, but you can.  You just have to develop a new way of thinking and solving problems.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

