<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx</link><description>A few short takes today, from questions I've received recently about LINQ in C# 3.0. The first question was " in the following code, does it really check every single non-negative integer, or does it use the knowledge that once you're beyond ten, you</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8481376</link><pubDate>Fri, 09 May 2008 21:36:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8481376</guid><dc:creator>Jacob</dc:creator><description>&lt;p&gt;The first questioner should look into Take/TakeWhile. Example:&lt;/p&gt;
&lt;p&gt;var smallNumbers = Enumerable.Range(0, int.MaxValue).TakeWhile(n =&amp;gt; n &amp;lt; 10);&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8481438</link><pubDate>Fri, 09 May 2008 21:54:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8481438</guid><dc:creator>Mark Sowul</dc:creator><description>&lt;p&gt;&amp;quot;Even leaving the obvious efficiency concern aside, the latter code reads better. It more clearly reflects the intention of the programmer.&amp;quot;&lt;/p&gt;
&lt;p&gt;Isn't that half of the point of LINQ, to allow for a limited degree of functional and declarative programming such that the &amp;quot;what&amp;quot; becomes more important than the &amp;quot;how&amp;quot;?&lt;/p&gt;
&lt;p&gt;Unless you have a significant, measurable performance difference, write what you mean!&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8481512</link><pubDate>Fri, 09 May 2008 22:12:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8481512</guid><dc:creator>Richard</dc:creator><description>&lt;p&gt;@Mark&lt;/p&gt;
&lt;p&gt;&amp;quot;Unless you have a significant, measurable performance difference, write what you mean!&amp;quot;&lt;/p&gt;
&lt;p&gt;You don't have to measure the performance to know that iterating to 2^31 in order to get 10 values is going to be inefficient. Efficiency versus readability is a continuous trade-off, can't always easily be fixed after the fact, and it's not just asymptotic differences that matter. If I can make my product 3x faster by making all my code 20% less readable (by, for instance, writing it in C++ rather than in Java), and that speed increase matters enough, then I'd better be aware of that before I write a single line of code.&lt;/p&gt;
&lt;p&gt;Premature optimization is bad, but believing that all optimization is premature is bad too.&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8481964</link><pubDate>Fri, 09 May 2008 23:45:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8481964</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;@Jacob: Was going to suggest to same, developers just don't know what to use most of the time :(&lt;/p&gt;
</description></item><item><title>IEnumerable&lt;T&gt;.Any() vs. IEnumerable&lt;T&gt;.Count() != 0</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8484660</link><pubDate>Sun, 11 May 2008 01:24:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8484660</guid><dc:creator>Jerome Laban</dc:creator><description>&lt;p&gt;An english version is available here . Apr&amp;#232;s avoir lu ce post d'Eric Lippert , je me suis rappel&amp;#233; que&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8489945</link><pubDate>Mon, 12 May 2008 02:20:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8489945</guid><dc:creator>Dean Harding</dc:creator><description>&lt;p&gt;&amp;quot;Accessing event logs from a remote machine over a slow network&amp;quot;&lt;/p&gt;
&lt;p&gt;What kind of developer wouldn't have seen that coming?&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8490424</link><pubDate>Mon, 12 May 2008 03:41:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8490424</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;A novice?&lt;/p&gt;
&lt;p&gt;Developers have to start somewhere, you know.&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8492655</link><pubDate>Mon, 12 May 2008 11:45:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8492655</guid><dc:creator>B0rG</dc:creator><description>&lt;p&gt;I'm wondering about this one: &lt;/p&gt;
&lt;p&gt;if (0 != customers.Count()) ...&lt;/p&gt;
&lt;p&gt;vs&lt;/p&gt;
&lt;p&gt;if (customers.Any()) ...&lt;/p&gt;
&lt;p&gt;does Count() always count all the records in the collection, or number of items is stored somewhere? &lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8492795</link><pubDate>Mon, 12 May 2008 12:16:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8492795</guid><dc:creator>James Hart</dc:creator><description>&lt;p&gt;@B0rG - well, if customers implements IList, then the Enumerable.Count() method takes a shortcut and reads the Count property. But for a general IEnumerable, there's no guarantee that the extension Count() method will find a quicker way to count it than to enumerate the whole collection. And it's perfectly possible to implement an IEnumerable that never terminates, so Count() on a general IEnumerable may simply never return.&lt;/p&gt;
&lt;p&gt;Calling Count() is essentially asking 'how many times do I have to call MoveNext() on an enumerator before I get an answer of 'false'?'. asking for 'Any()' is simply asking 'does the first call to MoveNext() on an enumerator return true?'&lt;/p&gt;
</description></item><item><title>re: Computers are dumb</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8493015</link><pubDate>Mon, 12 May 2008 13:05:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8493015</guid><dc:creator>Tom Kirby-Green</dc:creator><description>&lt;p&gt;The for-loop iteration is faster I belive because for built in System.Array's the JITer is able to emit efficient machine code that doesn't do range checking for each an every index look-up.&lt;/p&gt;
&lt;p&gt;I believe for this to work the boundary check must be inline to the 'for', that is to say:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; int[] data = new int[] { ... };&lt;/p&gt;
&lt;p&gt; &amp;nbsp; for (int i = 0; i &amp;lt; data.Length; i++)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Process(data[i]); &amp;nbsp; /// Details boring&lt;/p&gt;
&lt;p&gt;rather than:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; int[] data = new int[] { ... };&lt;/p&gt;
&lt;p&gt; &amp;nbsp; int length = data.Length;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; for (int i = 0; i &amp;lt; length; i++)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;Process(data[i]); &amp;nbsp; // Details boring&lt;/p&gt;
&lt;p&gt;But like all undocumented optimizations it would dangerous to over rely on this JIT optimization.&lt;/p&gt;
</description></item><item><title>IEnumerable&lt;T&gt;.Any() vs. IEnumerable&lt;T&gt;.Count() != 0</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8502094</link><pubDate>Wed, 14 May 2008 02:04:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8502094</guid><dc:creator>Jerome Laban</dc:creator><description>&lt;p&gt;An english version is available here . Apr&amp;#232;s avoir lu ce post d'Eric Lippert , je me suis rappel&amp;#233; que&lt;/p&gt;
</description></item><item><title>VCS Team Links for May 22, 2008</title><link>http://blogs.msdn.com/ericlippert/archive/2008/05/09/computers-are-dumb.aspx#8533331</link><pubDate>Thu, 22 May 2008 22:12:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8533331</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Rather than place the links to the most recent C# team content directly in Community Convergence , I&lt;/p&gt;
</description></item></channel></rss>