<?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>Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx</link><description>Escalation Engineer JeremyK asks in his blog this morning : how do you teach people this &amp;#8220;art&amp;#8221; of digging deep very quickly into unfamilar code that you had no hand in writing? I myself, I come from a very traditional process of learning how</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155353</link><pubDate>Mon, 14 Jun 2004 19:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155353</guid><dc:creator>Patrick Steele</dc:creator><description>&amp;quot;Don't write 'clever' code&amp;quot;.&lt;br&gt;&lt;br&gt;Agreed!!  We've got a bunch of code laying around with stuff like this:&lt;br&gt;&lt;br&gt;bComplete = (sState = &amp;quot;complete&amp;quot; ) ? true : false;&lt;br&gt;&lt;br&gt;Hello?  How about simply:&lt;br&gt;&lt;br&gt;bComplete = (sState = &amp;quot;complete&amp;quot;);&lt;br&gt;</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155356</link><pubDate>Mon, 14 Jun 2004 19:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155356</guid><dc:creator>Eric Lippert</dc:creator><description>I'd classify that as more &amp;quot;redundant&amp;quot; than &amp;quot;clever&amp;quot;.  &lt;br&gt;&lt;br&gt;I see that kind of thing all the time, particularly in VB/VBScript.  People seem to think that a conditional needs an operator.  &lt;br&gt;&lt;br&gt;If Blah = True Then&lt;br&gt;&lt;br&gt;instead of &lt;br&gt;&lt;br&gt;If Blah Then&lt;br&gt;&lt;br&gt;Of course, these two things have different meanings.  The former will execute the consequence only if Blah really is True.  The second will execute it if Blah is not False, which is rather different!  &lt;br&gt;&lt;br&gt;I should write a blog entry on that particular &amp;quot;gotcha&amp;quot;.  &lt;br&gt;</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155367</link><pubDate>Mon, 14 Jun 2004 19:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155367</guid><dc:creator>No one</dc:creator><description>What is shadowing?</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155376</link><pubDate>Mon, 14 Jun 2004 20:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155376</guid><dc:creator>Eric Lippert</dc:creator><description>What does this program do?&lt;br&gt;&lt;br&gt;void foo(void)&lt;br&gt;{&lt;br&gt;  int count = this-&amp;gt;CountFrobs();&lt;br&gt;  for( int count = 1 ; count &amp;lt; 10 ; ++ count)&lt;br&gt;  {&lt;br&gt;     print(count);&lt;br&gt;  }&lt;br&gt;  print(count);&lt;br&gt;}&lt;br&gt;&lt;br&gt;That's shadowing.  The inner variable shadows the outer local variable.  Not all languages support shadowing, but C and C++ do.</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155380</link><pubDate>Mon, 14 Jun 2004 20:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155380</guid><dc:creator>Christopher Hawkins</dc:creator><description>It sounds as though Jeremy is trying to teach non-coders to read code, which may not be entirely realistic.</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155387</link><pubDate>Mon, 14 Jun 2004 20:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155387</guid><dc:creator>Robert W. McLaws</dc:creator><description>I read a great book recently (not yet released) that focused on a very simple premise:&lt;br&gt;&lt;br&gt;Code craft is not about writing code that computers can read. A computer can understand o.e(q); but that doesn't mean you should use it.&lt;br&gt;&lt;br&gt;No, being a true coder comes from the understanding that you are not writing code for a computer. You are writing a language that other PEOPLE will need to read and understand.&lt;br&gt;&lt;br&gt;Some people would say &amp;quot;You should make sure you add lots of comments.&amp;quot; But isn't the goal to write code that doesn't need to be commented? Shouldn't your code use a consistent, intuitive structure on every level, from the directory to the class library?&lt;br&gt;&lt;br&gt;True masters of the craft write code that needs no comments, because it is completely apparent, through variable and function naming, what is going on. The only comments that should be neccessary are API documentation tags, which are wholly different from : 'Loop through the collection to enumerate the names&lt;br&gt;&lt;br&gt;If reading code is hard, it's only because developers are poor communicators. I talked about this concept in more detail a few months ago here: &lt;a target="_new" href="http://weblogs.asp.net/rmclaws/archive/2004/01/30/65445.aspx"&gt;http://weblogs.asp.net/rmclaws/archive/2004/01/30/65445.aspx&lt;/a&gt;</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155409</link><pubDate>Mon, 14 Jun 2004 20:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155409</guid><dc:creator>Mike Dimmick</dc:creator><description>I know some developers who've moved from VB 6 to C#:&lt;br&gt;&lt;br&gt;if ( blah == true )&lt;br&gt;{&lt;br&gt;}&lt;br&gt;&lt;br&gt;Aaargh!!</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155460</link><pubDate>Mon, 14 Jun 2004 21:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155460</guid><dc:creator>M.</dc:creator><description>There's a book on the subject:&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://www.spinellis.gr/codereading/"&gt;http://www.spinellis.gr/codereading/&lt;/a&gt;&lt;br&gt;&lt;br&gt;IMHO, it's very good.&lt;br&gt;</description></item><item><title>Book on reading code</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155472</link><pubDate>Mon, 14 Jun 2004 22:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155472</guid><dc:creator>Duane</dc:creator><description>A good and perhaps unique book, all about how to read code:&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://www.spinellis.gr/codereading/"&gt;http://www.spinellis.gr/codereading/&lt;/a&gt;&lt;br&gt;</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155771</link><pubDate>Tue, 15 Jun 2004 05:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155771</guid><dc:creator>Jeremy Kelly</dc:creator><description>Your post was interesting, but it didn't directly help my quandary. KC didn't include my entire post... I have been tasked with delivering a class on how to &amp;quot;read&amp;quot; source to troubleshoot issues. My role routinely involves utilizing these abilities to read, rationalize, and reverse engineer code, but how to convey these to others?</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155901</link><pubDate>Tue, 15 Jun 2004 10:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155901</guid><dc:creator>Dan Shappir</dc:creator><description>Jeremy, my best suggestion would be: try to grasp the coding style of the person who wrote that code. Most of us have our own coding style, which are often quit unique, even when the company we work for attempts to enforce coding guidelines. Often encountering a different coding style results in cognitive dissonance - you feel a great urge to &amp;quot;fix&amp;quot; that code, to transform it to your own style. Resist that urge. Instead assimilate that style and use your understanding of it to understand the code. It may even help to write down the rules of this code as you come to understand them.&lt;br&gt;&lt;br&gt;Also, try to take a top-down approach (there are even tools that can help you do that in some cases). Don't delve into functions you don't need to understand, you'll drown in the details (obviously in some cases you may not have a choice, for example if lots of globals are used).&lt;br&gt;&lt;br&gt;Bottom line: to understand complex code requires humility. See this:&lt;br&gt;&lt;a target="_new" href="http://www.wilk4.com/humor/humore17.htm"&gt;http://www.wilk4.com/humor/humore17.htm&lt;/a&gt;&lt;br&gt;&lt;br&gt;Eric, I disagree with one of your rules:&lt;br&gt;&lt;br&gt;&amp;gt; Variables with names like &amp;quot;i&amp;quot; are badness.  You can't easily search code without getting false positives.&lt;br&gt;&lt;br&gt;A variable name like &amp;quot;i&amp;quot; is badness if used as a global (oh the horror) or a member or even a parameter. It is IMO perfectly fine as an index for an inner loop, e.g.&lt;br&gt;&lt;br&gt;for (int i=0; i &amp;lt; length; ++i) a[i] = i;&lt;br&gt;&lt;br&gt;You never grep for such variables and the name &amp;quot;i&amp;quot; actually indicates the variable's use. OTOH this style does cause problems with languages that don’t support shadowing, such as JavaScript (which is why I like the functional style, where you don’t need such variables).&lt;br&gt;&lt;br&gt;I would add the following rule: a function should never be more than two screens in length and a loop should never be more than one screen (I actually try to keep both much shorter than that).</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#155990</link><pubDate>Tue, 15 Jun 2004 13:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155990</guid><dc:creator>peterb</dc:creator><description>At least if you're writing C code, lint will complain if you write:&lt;br&gt;&lt;br&gt;if (blah == TRUE) { ...&lt;br&gt;&lt;br&gt;rather than&lt;br&gt;&lt;br&gt;if (blah) { ...&lt;br&gt;&lt;br&gt;Of course, that brings up the whole &amp;quot;Why the hell isn't lint part of the compiler?&amp;quot; fiasco.</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#156310</link><pubDate>Tue, 15 Jun 2004 17:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156310</guid><dc:creator>Eric Lippert</dc:creator><description>I agree that if you keep the loops short, you can get away with cheap indexers.  But still, loops have this tendency to get longer and longer...  &lt;br&gt;&lt;br&gt;And it's not just grep, it's also searching using my editor's regexp search function which is easier if the variables are unique in the text.&lt;br&gt;&lt;br&gt;I personally will write loop indexers as &amp;quot;iFoo&amp;quot;, to call out that I'm indexing over an array of Foos.  I know other people who prefer to use ii, jj, kk as their loop indexers.  Short, clear, traditional, easy to search.</description></item><item><title>Reading Code Is Hard, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#156352</link><pubDate>Tue, 15 Jun 2004 21:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156352</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description /></item><item><title>Make the code amenable to tools</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#156553</link><pubDate>Tue, 15 Jun 2004 22:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156553</guid><dc:creator>Diomidis Spinellis</dc:creator><description>Another way to make the code amenable to tools: use a consistent coding style.  If the function names in function definitions always start in column 1 you can find them (with your editor or grep) with the regular expression &amp;quot;^name&amp;quot;.  &lt;br&gt;&lt;br&gt;</description></item><item><title>re: Loop indexing</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#156560</link><pubDate>Tue, 15 Jun 2004 22:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156560</guid><dc:creator>Diomidis Spinellis</dc:creator><description>I agree with the previous poster who said that a variable named &amp;quot;i&amp;quot; is not an unreasonable name for an array index in a short loop.  Another poster then reccommended using iFoo for indexing over an array of Foos.  We can actually do a lot better than that by letting the compiler do the job for us.  Instead of an integer index we can declare a pointer to an object of the array.  This ensures that we will never index objects of the wrong type.  Integer array indices are not connected in any way with the object they index and therefore force us to use naming hacks like iFoo; pointers on the other hand carry with them the required type information.</description></item><item><title>How do I debug a problem in someone elses code</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#158338</link><pubDate>Thu, 17 Jun 2004 19:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:158338</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#159175</link><pubDate>Fri, 18 Jun 2004 11:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159175</guid><dc:creator>Andrew Shuttlewood</dc:creator><description>If I get a lot of false positives (as above), you can chain the output of grep into another grep with -v&lt;br&gt;&lt;br&gt;so&lt;br&gt;&lt;br&gt;grep -r perfExecuteManifest | grep -v perfExecuteManifestInitialize &amp;gt;output.txt will prune them.&lt;br&gt;&lt;br&gt;But I accept it's still an arse, you have to KNOW about all of the possible false positives before you can do this.&lt;br&gt;</description></item><item><title>re: Reading Code Is Hard</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#159207</link><pubDate>Fri, 18 Jun 2004 12:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:159207</guid><dc:creator>Petr Kadlec</dc:creator><description>And what about grep -w perfExecuteManifest ?</description></item><item><title>Teaching the Skill of Reading Code</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#168336</link><pubDate>Tue, 29 Jun 2004 08:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:168336</guid><dc:creator>JeremyK's [MSFT] WebLog</dc:creator><description /></item><item><title>See Braidy Tester Read Code.  Read, Braidy Tester, Read!</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#183064</link><pubDate>Wed, 14 Jul 2004 18:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:183064</guid><dc:creator>The Braidy Tester</dc:creator><description /></item><item><title>Write Readable Code By Making Its Intentions Clear</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#2204023</link><pubDate>Fri, 20 Apr 2007 10:58:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2204023</guid><dc:creator>you've been HAACKED</dc:creator><description>&lt;p&gt;Write Readable Code By Making Its Intentions Clear&lt;/p&gt;
</description></item><item><title>Write Readable Code By Making Its Intentions Clear</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#2205435</link><pubDate>Fri, 20 Apr 2007 13:21:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2205435</guid><dc:creator>Community Blogs</dc:creator><description>&lt;p&gt;I don’t think it’s too much of a stretch to say that the hardest part of coding is not writing code,&lt;/p&gt;
</description></item><item><title>Write-only variables considered harmful? Or beneficial?</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#4795750</link><pubDate>Fri, 07 Sep 2007 01:30:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4795750</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;p&gt;I haven't forgotten that I promised to describe one more place where we insert an explicit conversion&lt;/p&gt;
</description></item><item><title>Reading Code Is Hard, Part Two</title><link>http://blogs.msdn.com/ericlippert/archive/2004/06/14/reading-code-is-hard.aspx#5403525</link><pubDate>Thu, 11 Oct 2007 21:38:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5403525</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;p&gt;I was thinking about this a bit more and talking with Larry Osterman yesterday, and I came up with some&lt;/p&gt;
</description></item></channel></rss>