<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.developerdotstar.com/community" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>developer.* Blogs - Functional Programming vs. OO - Comments</title>
 <link>http://www.developerdotstar.com/community/node/544</link>
 <description>Comments for &quot;Functional Programming vs. OO&quot;</description>
 <language>en</language>
<item>
 <title>The right tool...</title>
 <link>http://www.developerdotstar.com/community/node/544#comment-1446</link>
 <description>&lt;p&gt;My primary point was, as I noted, that it&#039;s not enough just to verify &quot;yup my language can do that&quot;.  The question is, will you use it?  Is it more efficient than the method you already knew?  If it isn&#039;t, you&#039;re not likely to use it.  And not likely to consider that it might be easier than what you&#039;re already comfortable with, if you try a &lt;i&gt;different&lt;/i&gt; language.  Sometimes doing the same job in a different way in the same language is worse, but doing it that way in a different language is just plain better.&lt;/p&gt;
&lt;p&gt;&quot;...Right tool for the job...&quot;&lt;/p&gt;
&lt;p&gt;Everyone knows some languages are good at some things and others are good at others.  But we&#039;ll never know what exactly those things are unless we shop around.  It&#039;s not enough to be &quot;sure that functional programming has its uses and its merits&quot;.  I&#039;d encourage you to take up the goal I did recently: find out what those uses and merits are!&lt;/p&gt;
&lt;p&gt;Joel&#039;s argument (and Paul Graham, and Steve Yegge, and... ) is that not only will you find new tools you never had before, but you&#039;ll find that you can think about solutions in ways you never did before.  And that will help you even if you stick with the old stand-by language.  (If it&#039;s expressive enough.  Doesn&#039;t matter how much you know about generics and dynamic typing, it won&#039;t make your PL/SQL more concise or elegant.  Bleh.)&lt;/p&gt;
</description>
 <pubDate>Thu, 24 Aug 2006 19:25:11 -0700</pubDate>
 <dc:creator>WaterBreath</dc:creator>
 <guid isPermaLink="false">comment 1446 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Dynamism . . .</title>
 <link>http://www.developerdotstar.com/community/node/544#comment-1444</link>
 <description>&lt;p&gt;. . . is I think the word WaterBreath is looking for above.&lt;/p&gt;
&lt;p&gt;I&#039;m not sure I understand David Koontz&#039;s point that:&lt;/p&gt;
&lt;p&gt;&lt;cite&gt;In your example to program in a functional style you&#039;d have to go around scattering map methods in each class or have your own base class from which everything else inherits.&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;That&#039;s not true at all. You could implement something like this any number of ways in Java, such as in a static method, or in a class that other methods instantiate and call methods on, or as some sort of remote service. &lt;/p&gt;
&lt;p&gt;Developers tend to get into my-language-is-better-than-yours pissing contests (again, I see Calvin peeing on various corporate logos -- see this &lt;a href=&quot;http://www.developerdotstar.com/community/node/542#comment-1364&quot;&gt;comment&lt;/a&gt; I made in another post), and I don&#039;t want play that game if at all possible (and I&#039;m not accusing either WB or DK of doing so either). I&#039;m sure that functional programming has its uses and its merits. My only point was that the particular problem Joel presented was certainly solveable in Java. I remain convinced that it is.&lt;/p&gt;
&lt;p&gt;I had occasion recently to re-visit &lt;a href=&quot;http://www.developerdotstar.com/community/thinking_in_sets&quot;&gt;a post of mine&lt;/a&gt; from last year in which I dug into the different mindsets developers get into when they think linearly (solving problems through iteration in code) and when they think in sets (which is how SQL operates). This discussion actually reminds me quite a bit the points I raised (and the larger point I think Joel was trying to make) that the development language you use affects how you think about solving problems, and that sometimes it can box you in.&lt;/p&gt;
</description>
 <pubDate>Thu, 24 Aug 2006 14:21:12 -0700</pubDate>
 <dc:creator>Rob MacGrogan</dc:creator>
 <guid isPermaLink="false">comment 1444 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>A more poingant example of first class functions</title>
 <link>http://www.developerdotstar.com/community/node/544#comment-1443</link>
 <description>&lt;p&gt;While it is certainly true that you can implement map as a method in the class, that is missing the point.  In a language with &quot;free-floating functions&quot; (which the rest of us simply call functions since everything in Java is a *method*), you can implement map once for ANY combination of list + function.  In your example to program in a functional style you&#039;d have to go around scattering map methods in each class or have your own base class from which everything else inherits.  Not particularly DRY.  Also, because of the type system you&#039;re either going to have to do some generics tricks or implement a ton of different map&#039;s to cover all the different combinations of methods and lists to iterate over.&lt;/p&gt;
&lt;p&gt;Perhaps an example is in order, this comes from Ruby which perhaps will be more to your syntactical tastes:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot;&gt;
&lt;pre&gt;list = [1,2,3,4,5,6] #array of numbers&lt;br /&gt;list.each {|i| puts i if i%2 == 0} #print out even nums&lt;br /&gt;list.each {|i| puts i if i&amp;gt;4} #56&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and then since you&#039;ve got the really most basic stuff like each going you can take this idea of passing in anonymous functions (called lambdas) and do all sorts of fun things&lt;/p&gt;
&lt;div class=&quot;codeblock&quot;&gt;
&lt;pre&gt;list.reject {|i| i &amp;gt; 4} #[1,2,3]&lt;br /&gt;list.partition {|i| i%2 == 0} #returns 2 lists [2,4,6], [1,3,5]&lt;br /&gt;list.inject {|sum, i| sum += i} #21&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;These methods and several others are available for any collection in any class in any file anywhere.  This is all without losing the namespaces that classes give you.  The point is, you can do C++ in C with function pointers, the fact that&#039;s it&#039;s possible doens&#039;t mean C is a good language for object oriented programming.  The same applies here to Java and functional programming, the language just doesn&#039;t support the needed functionality to make it useful.  As the previous commenter stated, C# 3.0 (while I detest MS and have never used C# professionally) is adding things like anonymous functions (lambdas) so you will be able to pull off *some* of these tricks there.&lt;/p&gt;
</description>
 <pubDate>Thu, 24 Aug 2006 12:56:31 -0700</pubDate>
 <dc:creator>David Koontz</dc:creator>
 <guid isPermaLink="false">comment 1443 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Dynamicity (is that a word?)</title>
 <link>http://www.developerdotstar.com/community/node/544#comment-1372</link>
 <description>&lt;p&gt;&amp;gt;What the OO solution to this problem gives you, though, is some nice name-spacing...&lt;/p&gt;
&lt;p&gt;C++ has namespace structures that are totally untethered from classes.  Anything you can declare in the global namespace, or in a class, or in a function, can be declared within a named namespace that you yourself create in code.&lt;/p&gt;
&lt;p&gt;&amp;gt;...the potential for type safety in your map method...&lt;/p&gt;
&lt;p&gt;The argument of proponents of functional and dynamically-typed languages is precisely that things like type safety, when applied universally, are limiting.  Generics and interface mechanisms were created specifically to get around these limitations.  They were added to Java and C++ to support behavior that are very natural in functional and dynamically typed languages.  That naturalness is key to the debate.&lt;/p&gt;
&lt;p&gt;&amp;gt;...a potentially much more readable batch of code&lt;/p&gt;
&lt;p&gt;This is quite subjective.  And it&#039;s one example of how learning dynamic languages can change how you think about programming.  I would argue that implementing in an OO language (esp. Java) these things that are inherently natural in functional and dynamic languages, is cumbersome, verbose, and rigid.  Functional and dynamic languages drive toward a goal of expressing this behavior with utmost concision and elegance.&lt;/p&gt;
&lt;p&gt;&amp;gt;there&#039;s no reason this can&#039;t be done in an OO language as easily as in a functional language&lt;/p&gt;
&lt;p&gt;The concision and elegance mentioned above naturally contribute to ease as well.  I understand the OO-minded view that functional and dynamically-typed languages encourage messy or disorganized code structure.  But I would contend that this is because people who have settled into OO and resided there for too long begin to see OO-style structure as a requirement for organization, when that&#039;s simply not true.  Think about it a little, and I think you&#039;ll see that this type of view is a bit closed-minded and a real barrier to advancement in any scientific or engineering pursuit.&lt;/p&gt;
&lt;p&gt;There have been multiple responses to Joel&#039;s post that in effect answer his question in the affirmative.  But I think Joel made a mistake when he asked that question.  In particular, I think he should have asked it differently, because I don&#039;t think he meant to ask whether the general behavior was possible.  Rather, I think his point was to ask how natural and elegant its expression is in language X.&lt;/p&gt;
&lt;p&gt;My answer to that question, in the context of Java, C++, and C#, is: not very.  (Though the planned feature additiosn I&#039;ve seen for C# 3.0 look very promising.  I think C# and its continued evolution is one of Microsoft&#039;s crowning achievements of recent years.)&lt;/p&gt;
</description>
 <pubDate>Thu, 10 Aug 2006 12:30:10 -0700</pubDate>
 <dc:creator>WaterBreath</dc:creator>
 <guid isPermaLink="false">comment 1372 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Functional Programming vs. OO</title>
 <link>http://www.developerdotstar.com/community/node/544</link>
 <description>&lt;p&gt;What the OO solution to this problem gives you, though, is some nice name-spacing, the potential for type safety in your map method and a potentially much more readable batch of code. What&#039;s the major issue with this?&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.developerdotstar.com/community/node/544&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.developerdotstar.com/community/node/544#comment</comments>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/20">Software Development</category>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/18">Java</category>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/5">Languages</category>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/140">Object Oriented Design and Programming</category>
 <pubDate>Wed, 09 Aug 2006 16:58:34 -0700</pubDate>
 <dc:creator>Rob MacGrogan</dc:creator>
 <guid isPermaLink="false">544 at http://www.developerdotstar.com/community</guid>
</item>
</channel>
</rss>
