<?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: Variables for clarification</title>
	<atom:link href="http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification</link>
	<description>The personal weblog of Peter Hosey.</description>
	<lastBuildDate>Tue, 17 Jan 2012 18:19:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: foo</title>
		<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/comment-page-1#comment-287314</link>
		<dc:creator>foo</dc:creator>
		<pubDate>Sun, 16 Aug 2009 09:56:11 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=1080#comment-287314</guid>
		<description>@Karl: here you have a reasonably modern optimizing compiler (based on gcc or llvm), which can do a lot, so one could expect that the compiler will do a good job. However your question remains pertinent, because the if clause, compatible with C, has lazy evaluation semantics, i.e. in C it is 100% legal to write things such as:

   int foo(bar_t *mybar) {
      if(mybar != NULL &amp;&amp; mybar-&gt;baz(quux))
         ...
}

The second test will only be done if the first test succeeds, and this is very important if the second test has side effects. Some code conventions forbid any function call in an if clause because side effects can be hard for the programmer to predict.

So in the original, complex version of the test in this blog entry, the generated code would only perform the tests as necessary. In the second &quot;improved&quot; version, the tests can only be optimized away if the compiler can be sure that 1) their results are not needed later on (this is a common optimization), and 2) they have no side effect.

All in all, I really suspect the compiler can only produce the same code if the object methods used above are in header files. But of course, you should only care about this kind of detail if you are looking at a hot spot in your code.</description>
		<content:encoded><![CDATA[<p>@Karl: here you have a reasonably modern optimizing compiler (based on gcc or llvm), which can do a lot, so one could expect that the compiler will do a good job. However your question remains pertinent, because the if clause, compatible with C, has lazy evaluation semantics, i.e. in C it is 100% legal to write things such as:</p>
<p>   int foo(bar_t *mybar) {<br />
      if(mybar != NULL &amp;&amp; mybar-&gt;baz(quux))<br />
         &#8230;<br />
}</p>
<p>The second test will only be done if the first test succeeds, and this is very important if the second test has side effects. Some code conventions forbid any function call in an if clause because side effects can be hard for the programmer to predict.</p>
<p>So in the original, complex version of the test in this blog entry, the generated code would only perform the tests as necessary. In the second &#8220;improved&#8221; version, the tests can only be optimized away if the compiler can be sure that 1) their results are not needed later on (this is a common optimization), and 2) they have no side effect.</p>
<p>All in all, I really suspect the compiler can only produce the same code if the object methods used above are in header files. But of course, you should only care about this kind of detail if you are looking at a hot spot in your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Kuehn</title>
		<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/comment-page-1#comment-287176</link>
		<dc:creator>Karl Kuehn</dc:creator>
		<pubDate>Sat, 15 Aug 2009 04:01:39 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=1080#comment-287176</guid>
		<description>One of the questions I always ask myself when I am looking at my own code like this is what will the compiler actually do with this? I honestly don&#039;t know the answer, but it is possible that both of them will come out with the same resultant binaries. Anyone know the answer?</description>
		<content:encoded><![CDATA[<p>One of the questions I always ask myself when I am looking at my own code like this is what will the compiler actually do with this? I honestly don&#8217;t know the answer, but it is possible that both of them will come out with the same resultant binaries. Anyone know the answer?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/comment-page-1#comment-287130</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Fri, 14 Aug 2009 21:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=1080#comment-287130</guid>
		<description>Patrick Burleson:

&lt;blockquote&gt;So is the After code what the Before looked like at first?&lt;/blockquote&gt;

Huh? Then it wouldn&#039;t be After, would it?

&lt;blockquote&gt;What was the original code and was the comment there?&lt;/blockquote&gt;

&lt;p&gt;The code went through four generations, two of which exist in version control:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://growl.info/hg/growl-development/file/c6a0bfc2f06a/Extras/GrowlTunes/GrowlTunesController.m#l507&quot; rel=&quot;nofollow&quot;&gt;What I started working on.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The Before code with that comment.&lt;/li&gt;
&lt;li&gt;The Before code as seen above.&lt;/li&gt;
&lt;li&gt;After.&lt;/li&gt;
&lt;/ol&gt;
</description>
		<content:encoded><![CDATA[<p>Patrick Burleson:</p>
<blockquote cite="http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification#comment-"><p>So is the After code what the Before looked like at first?</p>
</blockquote>
<p>Huh? Then it wouldn&#8217;t be After, would it?</p>
<blockquote cite="http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification#comment-"><p>What was the original code and was the comment there?</p>
</blockquote>
<p>The code went through four generations, two of which exist in version control:</p>
<ol>
<li><a href="http://growl.info/hg/growl-development/file/c6a0bfc2f06a/Extras/GrowlTunes/GrowlTunesController.m#l507" rel="nofollow">What I started working on.</a></li>
<li>The Before code with that comment.</li>
<li>The Before code as seen above.</li>
<li>After.</li>
</ol>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Burleson</title>
		<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/comment-page-1#comment-287116</link>
		<dc:creator>Patrick Burleson</dc:creator>
		<pubDate>Fri, 14 Aug 2009 19:35:07 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=1080#comment-287116</guid>
		<description>So is the After code what the Before looked like at first? What was the original code and was the comment there?

I agree the second set of code is much easier to read and see what&#039;s being checked and probably doesn&#039;t need a comment.</description>
		<content:encoded><![CDATA[<p>So is the After code what the Before looked like at first? What was the original code and was the comment there?</p>
<p>I agree the second set of code is much easier to read and see what&#8217;s being checked and probably doesn&#8217;t need a comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Fisher</title>
		<link>http://boredzo.org/blog/archives/2009-08-14/variables-for-clarification/comment-page-1#comment-287103</link>
		<dc:creator>Steven Fisher</dc:creator>
		<pubDate>Fri, 14 Aug 2009 18:37:04 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=1080#comment-287103</guid>
		<description>There&#039;s a real art to which temporary variables you use. In addition to being self-documenting now, you&#039;ll also find it much easier to debug. A breakpoint on the if line will give you access to the outcomes of each of the subconditions.

This is something that a lot of Objective-C programmers wouldn&#039;t do. I&#039;ve flip-flipped on this. The idea of temporaries, particularily when sending messages to them, seems counter to the language flow.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a real art to which temporary variables you use. In addition to being self-documenting now, you&#8217;ll also find it much easier to debug. A breakpoint on the if line will give you access to the outcomes of each of the subconditions.</p>
<p>This is something that a lot of Objective-C programmers wouldn&#8217;t do. I&#8217;ve flip-flipped on this. The idea of temporaries, particularily when sending messages to them, seems counter to the language flow.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.134 seconds -->

