<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Naming and Body Language in Functional Code</title>
    <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Naming and Body Language in Functional Code</title>
      <description>&lt;p&gt;I wrote a blog the other day about functional refactoring and I had what I thought was a good example:

&lt;code&gt;&lt;pre&gt;
absPosition :: Buffer -&amp;gt; Int
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    foldr ((+).length) 0 . take y . terminatedLines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;Almost immediately, I saw replies on a couple of forums (including this one) which pointed out that I could&amp;#8217;ve written the code this way:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    sum . map length . take y . terminatedLines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;It&amp;#8217;s funny, I thought of using &lt;code&gt;sum&lt;/code&gt; instead of &lt;code&gt;foldr&lt;/code&gt; back when I was using Haskell&amp;#8217;s line function.  The code I had looked like this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    foldr ((+).((+1).length)) 0 . take y . lines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;But, I realized that the code wasn&amp;#8217;t in great shape for &lt;code&gt;sum&lt;/code&gt;, so I created &lt;code&gt;terminatedLines&lt;/code&gt;, used it and promptly forgot to do the refactoring I set out to do.

&lt;code&gt;&lt;pre&gt;
terminatedLines :: String -&amp;gt; [String]
terminatedLines = map (++ "\n") . lines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;From an imperative point of view, &lt;code&gt;terminatedLines&lt;/code&gt; looks a bit silly: &lt;i&gt;What?? You&amp;#8217;re going to append a newline to each line in a list of lines you just created just so that you can count it??&lt;/i&gt; But, I suspect 
that it isn&amp;#8217;t that bad.  The evaluator pulls values from each line and as it reaches the end of one it should just put a newline at the end of it.  If I&amp;#8217;m wrong about this, please let me know.

&lt;p&gt;In any case, I agree that the code looks better with &lt;code&gt;sum&lt;/code&gt; that it does with &lt;code&gt;foldr (+) 0&lt;/code&gt;.  The big question is &amp;#8211; should we refactor any more?

&lt;p&gt; Someone with the handle &lt;i&gt;sterl&lt;/i&gt; suggested a very cool trick.  I could drop the where clause like this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = 
  x + (sum . map length . take y . terminatedLines) contents
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;And then move on to this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = 
  sum . (x:) . map length . take y . terminatedLines $ contents
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;What&amp;#8217;s going on here?  Well as &lt;i&gt;sterl&lt;/i&gt; put it, we&amp;#8217;re summing anyway so why not prepend the &lt;code&gt;x&lt;/code&gt; onto the list that we are already summing? 

&lt;p&gt;Part of me likes this and part of me doesn&amp;#8217;t.  One the one hand, it&amp;#8217;s brief, but on the other hand, the code isn&amp;#8217;t telling us why it is doing what it is doing anymore. In the original code, there is an algorithm:
&lt;blockquote&gt;To get the absolute position, add the x position of the location to the sum of the lengths of all of the previous lines.&lt;/blockquote&gt;

&lt;p&gt;In the new code, the algorithm is:
&lt;blockquote&gt;To get the absolute position, sum the current x position with the lengths of all of the previous lines.&lt;/blockquote&gt;

&lt;p&gt;Wait, that&amp;#8217;s sort of the same, isn&amp;#8217;t it?

&lt;p&gt;This example points to a fundamental dilemma that I have with naming in Haskell.  I&amp;#8217;m used to introducing names in lower-level languages to bridge the gap between intention and mechanism, but what happens when your mechanism is so high-level that it can speak for itself?  Maybe we don&amp;#8217;t need names as much?

&lt;p&gt;Now, I know as I write this that someone is going to look at this as an extreme statement.  It isn&amp;#8217;t. Names are useful, and indispensable, but really they are only one of several ways of communicating meaning.  In each case, we have to pick the right tool for the job.  With Haskell, I think that programmers communicate with structure as much as they communicate with names.  It&amp;#8217;s the body-language of their code.</description>
      <pubDate>Tue, 11 Aug 2009 12:25:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:571c0f66-0389-492d-93c5-2992eedf53af</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Microsoft Office</title>
      <description>&lt;p&gt;This article is GREAT it can be EXCELLENT JOB and what a great tool!&lt;/p&gt;</description>
      <pubDate>Fri, 13 Jan 2012 20:55:54 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:01240f27-38e5-44d1-a51d-7c953417cf70</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-197765</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Backup iphone sms</title>
      <description>&lt;p&gt;A buffer is a better way.
Anyway. A good method to backup files on iPhone for you.&lt;/p&gt;</description>
      <pubDate>Sat, 07 Jan 2012 06:13:34 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:366fc650-1f7f-4e6e-88ee-059a95baa64f</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-195896</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by bagsupplyer</title>
      <description>&lt;p&gt;I really enjoy your articles. Very well written. 
&lt;a href="http://www.bagsupplyer.com/Guess-n1105/" rel="nofollow"&gt;New fashion women Guess Purses for wholesale on line from China free shipping&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 06 Sep 2011 03:47:05 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:6495e3ac-f267-446f-9eb2-a2bf432bb3fa</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-137406</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by http://www.salecoach-bag.com</title>
      <description>&lt;p&gt;.However be cautious, &lt;a href="http://www.salecoach-bag.com/" rel="nofollow"&gt;&lt;strong&gt;coach poppy&lt;/strong&gt;&lt;/a&gt;
 handbags are accessible in finest covering which replica makers acclimate to a little admeasurement but they are never fabricated in plastic; watch out, artificial pieces may be absolute affected pieces. Today the appearance trend is new but back the morrow comes, you see article new. Wherever possible, &lt;a href="http://www.salecoach-bag.com/coach-hobos-c-3.html/" rel="nofollow"&gt;&lt;strong&gt;coach hobos&lt;/strong&gt;&lt;/a&gt;
handbags with 18-carat coach and amuse yourself that whether they alive up to the brilliant affection the austere &lt;a href="http://www.salecoach-bag.com/coach-satchels-c-7.html/" rel="nofollow"&gt;&lt;strong&gt;coach satchels&lt;/strong&gt;&lt;/a&gt;angle for.&lt;/p&gt;</description>
      <pubDate>Mon, 04 Jul 2011 07:01:04 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:17450d3a-451b-4a14-bca6-ffd52c5b7067</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-114488</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by okey oyunu oyna </title>
      <description>&lt;p&gt;useful code. Thanks.&lt;/p&gt;


	&lt;p&gt;internette g&#246;r&#252;nt&#252;l&#252; olarak &lt;a href="http://www.okeyoyunu-oyna.com" rel="nofollow"&gt;okey oyunu oyna&lt;/a&gt;, ger&#231;ek kisilerle tanis,
 turnuva heyecanini yasa.&lt;/p&gt;</description>
      <pubDate>Thu, 28 Apr 2011 15:33:46 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8a325dab-f21d-4420-b725-2b98417f79b4</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-92806</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by smartbargainonline</title>
      <description>&lt;p&gt;Any lady with &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale beads&lt;/a&gt; wedding on the brain will be dropping not so faint hints beside the &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale jewelry beads&lt;/a&gt;,&lt;a href="www.ayliss.co.uk" rel="nofollow"&gt;wholesale beads&lt;/a&gt; way so pay consideration when you&#8217;re receiving prepared to pop &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale pandora beads&lt;/a&gt; the query. You can also seem at the jewelry she already owns to get an clue of her chic, especially regarding what type of &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale fashion jewelry&lt;/a&gt; metal she loves. Keep in mind that she will be got up in this ring for the rest of her life so make definite to choose something that suits her personality.&lt;/p&gt;</description>
      <pubDate>Sat, 02 Apr 2011 20:11:20 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:d741dc95-0b51-4d6d-8611-20c2a92e0d08</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-78657</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by http://www.smartbargainonline.com</title>
      <description>&lt;p&gt;Any lady with &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale beads&lt;/a&gt; wedding on the brain will be dropping not so faint hints beside the &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale jewelry beads&lt;/a&gt;,&lt;a href="www.ayliss.co.uk" rel="nofollow"&gt;wholesale beads&lt;/a&gt; way so pay consideration when you&#8217;re receiving prepared to pop &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale pandora beads&lt;/a&gt; the query. You can also seem at the jewelry she already owns to get an clue of her chic, especially regarding what type of &lt;a href="http://www.smartbargainonline.com" rel="nofollow"&gt;wholesale fashion jewelry&lt;/a&gt; metal she loves. Keep in mind that she will be got up in this ring for the rest of her life so make definite to choose something that suits her personality.&lt;/p&gt;</description>
      <pubDate>Thu, 31 Mar 2011 20:36:56 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9781c104-197b-4988-b20a-76824fd13502</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-77886</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by mobile screening equipment</title>
      <description>&lt;p&gt;KEESTRACK?manufacturing expert of mobile crusher and mobile screening equipment. Company engaged in the research &amp;#38; development, manufacture, sales of track screening machine,mobile screening,cone crusher,jaw crusher,impact crusher,mobile screening equipment,mobile crushing equipment, till now we are proud to say we are at front of the industry.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Feb 2011 23:36:49 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:86ef1782-c33f-40f1-8f0f-ad948839448b</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-67599</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by mechanical Seal</title>
      <description>&lt;p&gt;This article is very usefull for me! I can see that you are putting a lots of efforts into your blog. I will keep watching in your blog, thanks.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Feb 2011 23:30:55 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d6906573-80e7-46ca-af90-c5dfcddb8e27</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-67573</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by rolexes watches </title>
      <description>&lt;p&gt;As a matter of truth, you will find some factors for individuals to decide the value of the &lt;a href="http://www.replicawatchesuk.org.uk/rolex-watches-c-93.html" rel="nofollow"&gt;rolex watches&lt;/a&gt;. In order to get precious &lt;a href="http://www.rolexreplicasuk.co.uk/" rel="nofollow"&gt;rolexes watches&lt;/a&gt; for collecting, you&amp;#8217;ll want to pay attention to the following aspects. At 1st, you need to judge the amount of the &lt;a href="http://www.rolexreplicasuk.co.uk/" rel="nofollow"&gt;fake rolex&lt;/a&gt;. The amount of the &lt;a href="http://www.rolexreplicasuk.co.uk/rolex-datejust-c-2.html" rel="nofollow"&gt;Rolex DateJust&lt;/a&gt; watches existing in &lt;a href="http://www.rolexreplicasuk.co.uk/" rel="nofollow"&gt;rolex watches&lt;/a&gt; the world is crucial. If &lt;a href="http://www.rolexreplicasuk.co.uk/rolex-daytona-c-6.html" rel="nofollow"&gt;Rolex Daytona&lt;/a&gt; is exclusive, and it has a small amount within the world, &lt;a href="http://www.newreplicawatches.co.uk/" rel="nofollow"&gt;Swiss Replica Watch&lt;/a&gt; is going to become far more useful &lt;a href="http://www.replica-watches-uk.net/" rel="nofollow"&gt;replica watches&lt;/a&gt; with the development of years. A widespread &lt;a href="http://www.copywatches.net/" rel="nofollow"&gt;Discount Watches&lt;/a&gt; just isn&amp;#8217;t worth to collect. Useful &lt;a href="http://www.rolexreplicasuk.co.uk/rolex-day-date-c-4.html" rel="nofollow"&gt;Rolex Day Date&lt;/a&gt; are available in tiny amounts. The distinct looks of these designer &lt;a href="http://www.replicawatchesuk.org.uk/" rel="nofollow"&gt;fake watches&lt;/a&gt; are extremely unique. In most models, the face dials generally feature a layered design. This makes the brand genuinely intriguing and attractive. The &lt;a href="http://www.replicawatchesuk.org.uk/" rel="nofollow"&gt;cheap watches&lt;/a&gt; are created from a few of the finest supplies utilized in contemporary &lt;a href="http://www.replicawatchesuk.org.uk/breitling-watches-c-108.html" rel="nofollow"&gt;Breitling Watches&lt;/a&gt; generating. &lt;a href="http://www.copywatches.net/" rel="nofollow"&gt;Copy Watches&lt;/a&gt; supplies incorporate solid &lt;a href="http://www.newreplicawatches.co.uk/" rel="nofollow"&gt;Fake Watches&lt;/a&gt; state and refined stainless steel, diamonds, reinforced crystals and other precious stones. In some models, the bracelets consist of a mixture of gold and stainless steel while a much more casual leather band is also available. The &lt;a href="http://www.replicawatchesuk.org.uk/omega-watches-c-125.html" rel="nofollow"&gt;Omega Watches&lt;/a&gt; of Raymond Weil are mysterious and intriguing on account of the special textured layering of the front faces. Do not buy sport &lt;a href="http://www.replicawatchesuk.org.uk/cartier-watches-c-135.html" rel="nofollow"&gt;Cartier Watches&lt;/a&gt; if you are an office lady. The &lt;a href="http://www.rolexreplicasuk.co.uk/" rel="nofollow"&gt;replica watches&lt;/a&gt; are an individual belonging that represents the taste and the style of a person. &lt;a href="http://www.copywatches.net/" rel="nofollow"&gt;Imitation Watches&lt;/a&gt; will be easy for you if you have already known about yourself well. At last, we bet you can find the ideal women&amp;#8217;s &lt;a href="http://www.replica-watches-uk.net/" rel="nofollow"&gt;replica watches uk&lt;/a&gt; for the women in your life as long as you do research correctly.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Feb 2011 03:45:11 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e60178ee-19da-4d01-bd94-f78e70ea7dad</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-67423</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Criminal Records</title>
      <description>&lt;p&gt;I think that programmers communicate with structure as much as they communicate with names. It&#8217;s the body-language of their code.&lt;/p&gt;</description>
      <pubDate>Wed, 09 Feb 2011 11:40:38 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:fe4ad9c4-9135-4709-833c-d4b6c5ce69a8</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-61491</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by accounting services</title>
      <description>&lt;p&gt;I suppose the reason the practice gets on my nerves so much is because I tend to run into the mid-level-skill types &#8211; the people who think they&#8217;re much cleverer than they are. There&#8217;s nothing that makes a team member want to step back and watch a drowning man go under, than hearing, &#8220;Jeez, can&#8217;t you read?!? It&#8217;s OBVIOUS what my program does! It&#8217;s called &#8216;addStudentToTutors&#8217;!&#8221; It&#8217;s obvious what the program is supposed to do, yes&#8230;&lt;a href="http://www.admgroupllc.com/" rel="nofollow"&gt;accounting services&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 20 Jan 2011 09:29:11 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:35e7b53b-1745-410f-8831-49e88283f4a3</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-58159</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by dvdsoft</title>
      <description>&lt;p&gt;With the right tool, you can easily burn &lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-mp4-mpeg4-to-dvd.html" rel="nofollow"&gt;mp4 to dvd&lt;/a&gt; and &lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-itunes-to-dvd.html" rel="nofollow"&gt;itunes to dvd&lt;/a&gt;. Also, you can use &lt;a href="http://www.dvd-creator-converter.com/media-converter/" rel="nofollow"&gt;drm removal tool&lt;/a&gt;  to &lt;a href="http://www.dvd-creator-converter.com/tutorials/remove-drm-protection.html" rel="nofollow"&gt;remove drm protection&lt;/a&gt; from  itunes, zune, amazon legally. 
&lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-wmv-to-dvd.html" rel="nofollow"&gt;wmv to dvd&lt;/a&gt;, &lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-quicktime-mov-to-dvd.html" rel="nofollow"&gt;mov to dvd&lt;/a&gt;, &lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-mp4-mpeg4-to-dvd.html" rel="nofollow"&gt;mp4 to dvd&lt;/a&gt;, &lt;a href="http://www.dvd-creator-converter.com/tutorials/convert-itunes-to-dvd.html" rel="nofollow"&gt;itunes to dvd&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 05 Jan 2011 20:26:28 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:5df5794b-ab96-49e0-8f86-89a67e3da54f</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-54486</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by http://www.blacktowhiteiphone4.com</title>
      <description>&lt;p&gt;Apple&amp;#8217;s launch of the&lt;a href="http://www.blacktowhiteiphone4.com" rel="nofollow"&gt; iPhone 4 white&lt;/a&gt; has seen the greatest excitement for a new phone ever, with HD video recording, a super high-res screen and ridiculously slim dimensions, it&amp;#8217;s not hard to see why its so popular in the world.&lt;/p&gt;</description>
      <pubDate>Wed, 22 Dec 2010 20:18:14 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2b9bfb52-84e4-41b5-a4bc-1ba6bd180c5c</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-51151</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by FLV extractor</title>
      <description>&lt;p&gt;i have read it&lt;/p&gt;</description>
      <pubDate>Wed, 07 Apr 2010 03:47:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c230ef0c-49f8-4f6f-b005-580572656066</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-9304</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Walt "BMeph" Rorie-Baety</title>
      <description>&lt;p&gt;I personally love the terseness of functional programming for a very good reason: It breaks the ungodly, pretentious habit programmers have of &amp;#8220;nice-naming&amp;#8221; &amp;#8211; that is, naming functions and procedures with names that suggest what the function is meant to do, but doesn&amp;#8217;t.&lt;/p&gt;


	&lt;p&gt;I suppose the reason the practice gets on my nerves so much is because I tend to run into the mid-level-skill types &amp;#8211; the people who think they&amp;#8217;re much cleverer than they are. There&amp;#8217;s nothing that makes a team member want to step back and watch a drowning man go under, than hearing, &amp;#8220;Jeez, can&amp;#8217;t you read?!? It&amp;#8217;s OBVIOUS what my program does! It&amp;#8217;s called &amp;#8216;addStudentToTutors&amp;#8217;!&amp;#8221; It&amp;#8217;s obvious what the program is supposed to do, yes&amp;#8230;&lt;/p&gt;


	&lt;p&gt;One of the nice thing about doing all of those Flying Wallendas-style functions, is that it breaks your functions up into dense nuggets of power, that you are then &amp;#8220;compelled&amp;#8221; to comment. It&amp;#8217;s never bad to just throw a line of commentary that says: &amp;#8221;&amp;#8212;&amp;#8216;withLines&amp;#8217; takes a function, and makes a new function that applies &amp;#8216;lines&amp;#8217; to its argument, runs your function on that, and then does &amp;#8216;unlines&amp;#8217; to the result&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;Functional programming in general, gives you the idea that you&amp;#8217;re describing what you want to happen, instead of what you have to set up to get it to happen.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Aug 2009 18:58:38 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:eb7474ba-cc1f-4984-af8c-7df335c8939b</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-4001</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by sterl.</title>
      <description>&lt;p&gt;When to extract and not to is a good question. I tend to only give names and extract when there&amp;#8217;s some redundancy to be exploited. Otherwise, it always makes sense to me to inline&amp;#8212;proper formatting and occasional comments are enough otherwise. Nice Haskell can read very fluently already, I think.&lt;/p&gt;


	&lt;p&gt;Viewing the simple stuff inline can also expose all sorts of other nice optimizations such as why &amp;#8220;terminatedLines&amp;#8221; can be replaced with, e.g., Jake&amp;#8217;s very elegant code above.&lt;/p&gt;


	&lt;p&gt;&amp;#8220;editor combinators&amp;#8221; and variants such as the above are really nice ways to denoise your code&amp;#8212;abstracting out views on data, so to speak, rather than operations on it.&lt;/p&gt;</description>
      <pubDate>Mon, 17 Aug 2009 12:18:48 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:7cf0a0b0-484e-4d4e-b012-2ca27268f3d3</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3988</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by nemo godfrey</title>
      <description>&lt;p&gt;Michael Feathers,&lt;/p&gt;


	&lt;p&gt;re: Dirk: terminatedLines isn&#8217;t a good idea&lt;/p&gt;


	&lt;p&gt;While [1,2,3] + [4,5,6] indeed reduces to 1:(2:([3]+[4,5,6])), the cost of that reduction is the length of the first list. In the context of your map (++&amp;#8221;\n&amp;#8221;) code, it&amp;#8217;s decidedly non-trivial. That&amp;#8217;s Dirk&amp;#8217;s point.&lt;/p&gt;


	&lt;p&gt;In other words, append doesn&amp;#8217;t do automagical, never mind zero-cost, consing &amp;#8220;at the end of the consumption.&amp;#8221; That said, you might want to check out difference lists.&lt;/p&gt;</description>
      <pubDate>Wed, 12 Aug 2009 10:37:14 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1767aa67-f72a-4101-9708-fd799c7bf47f</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3931</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Michael Feathers</title>
      <description>&lt;p&gt;Mark: Thx.&lt;/p&gt;


	&lt;p&gt;Dirk: I was hoping that with lazy evaluation, the reduction order for something like [1,2,3] + [4,5,6] would be 1:(2:([3]+[4,5,6])).  In other words, we consume elements from the head and then the append happens sort of as a cons and at end of the consumption.  from the definition of (++) it looks like that is what happens.&lt;/p&gt;</description>
      <pubDate>Wed, 12 Aug 2009 07:49:54 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c4fb3dd3-7f02-4a50-a507-2c02654e8bbf</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3929</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Dirk</title>
      <description>&lt;p&gt;Actually, terminatedLines isn&amp;#8217;t a good idea, because (++) is slow (Rule of thumb: Putting things in front of a list is good, appending things at the end is bad, because in the latter case you first have to traverse the whole list).&lt;/p&gt;


	&lt;p&gt;For the example in question, I&amp;#8217;d just use a list comprehension:&lt;/p&gt;


&lt;pre&gt;
absPosition (Buffer (x,y) contents) = 
  x + sum [length l + 1 | l &amp;lt;- take y $ lines $ contents]
&lt;/pre&gt;

	&lt;p&gt;No need to make code harder to read than necessary.&lt;/p&gt;</description>
      <pubDate>Wed, 12 Aug 2009 06:24:07 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:bd4075ad-e700-41a3-9969-b16d8c9d6fc8</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3928</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Mark Wotton</title>
      <description>&lt;p&gt;(++) might be space equivalent, but I think it&amp;#8217;s not time equivalent:&lt;/p&gt;


&lt;pre&gt;
14:22 ~ % cat test.hs
import System

atEnd [] = []
atEnd (x:xs) = (atEnd xs) ++ [x]

main = do
  (n:_) &amp;lt;- getArgs
  putStrLn $ show $ sum$  atEnd [1..(read n)]

14:21 ~ % time ./test 10000 
50005000
./test 10000  1.26s user 0.02s system 96% cpu 1.332 total

14:22 ~ % cat test2.hs
import System

atBeginning [] = []
atBeginning (x:xs) = [x] ++ (atBeginning xs)

main = do
  (n:_) &amp;lt;- getArgs
  putStrLn $ show $ sum$  atBeginning [1..(read n)]

14:22 ~ % time ./test2 10000     
50005000
./test 10000  0.00s user 0.00s system 74% cpu 0.008 total
&lt;/pre&gt;</description>
      <pubDate>Tue, 11 Aug 2009 23:25:10 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:5a973e3a-2d64-4ae7-8b48-103284220e41</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3923</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by wren ng thornton</title>
      <description>&lt;p&gt;@Matthew: Taking anything to extremes is liable to be more trouble than it&amp;#8217;s worth, but these examples are hardly extreme. As for &amp;#8220;unpacking the definition&amp;#8221;, using function composition and eschewing names for intermediate parts often simplifies the reading because there is less to unpack. In the C/Java/Perl world I often have to run around in circles reading function after function before finally getting to the real code; in Haskell things are usually a lot more direct.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Aug 2009 23:08:45 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f92aaabe-a8b2-44c8-9e8c-891f4f3dda3c</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3922</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Samuel A. Falvo II</title>
      <description>&lt;p&gt;@Matthew: You don&amp;#8217;t understand functional programming, so of course this looks very foreign to you.  And, by understand, I truly mean eat, breath, sleep, and think in it.  You&amp;#8217;re an OO coder, and it shows, &lt;strong&gt;just&lt;/strong&gt; by your comment.&lt;/p&gt;


	&lt;p&gt;@Michael: Matthew&amp;#8217;s point is valid, but what I think you&amp;#8217;re going through is the classic &amp;#8220;newbie&amp;#8221; phase of functional programming.  You know just enough to be dangerous&amp;#8212;that is, you can speak the language, but you&amp;#8217;re not fluent in it like a native coder/speaker would be.  As you indicate, much of functional coding is body language&lt;/p&gt;


	&lt;p&gt;The funny thing is, Lisp and Forth coders have been trying to tell people this FOR DECADES.  The real question is, why hasn&amp;#8217;t anyone been listening?&lt;/p&gt;</description>
      <pubDate>Tue, 11 Aug 2009 19:58:27 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9f9390a4-da5b-4ba1-b67e-b8c58c1bfb23</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3919</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Jake McArthur</title>
      <description>&lt;p&gt;Matthew: I think my version is a good example of the goal of this whole exercise, though. I have expressed the whole idea of &amp;#8220;take y lines, get the length of that, then add x to that&amp;#8221; rather clearly, I think. Far more clearly than the original, certainly.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Aug 2009 17:56:16 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:7c06205b-bad3-4159-8b84-79c72555b3c4</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3918</link>
    </item>
    <item>
      <title>"Naming and Body Language in Functional Code" by Michael Feathers</title>
      <description>&lt;p&gt;Matthew: I agree.  The question seems to be where do you stop?  I suspect a lot of it has to do with what you assume about your audience.. whether some idioms common enough to avoid head-scratching.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Aug 2009 17:55:39 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ea6415c-ebc6-431f-8dab-fe259a7707f9</guid>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code#comment-3917</link>
    </item>
  </channel>
</rss>

