﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Marcel Popescu commented on Common issues found in code review</title><description>{} are noise, only there because the compiler can't figure out what statements are part of a branch. I can - the ones that are indented. That's why I remove the {} wherever I can :) But yea, I've seen that most people prefer it the other way around.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment17</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment17</guid><pubDate>Wed, 29 Oct 2008 08:45:45 GMT</pubDate></item><item><title>Benny Thomas commented on Common issues found in code review</title><description>Good call, Daniel
  
  
I didn't see the workspace.IsBatch problem,  but this may be a preemptive strike and not needed.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment16</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment16</guid><pubDate>Thu, 02 Oct 2008 11:19:49 GMT</pubDate></item><item><title>Dag commented on Common issues found in code review</title><description>@sheraz: with Linq:  list.ToArray() (or even list.ToList().ToArray() if you prefer)
  
  
I prefer to use string.IsNullOrEmpty(), not sure if your StringHelper.IsEmpty contains any extra magic though.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment15</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment15</guid><pubDate>Wed, 01 Oct 2008 09:32:04 GMT</pubDate></item><item><title>Daniel Crabtree commented on Common issues found in code review</title><description>@Arild, quite true. I have no idea how I overlooked the Any function for this purpose.
  
  
@Rik Hemsley, your simplification is not consistent with the original code. 
  
workspace.IsBatch = queue.Has(w =&gt; w.IsBatch);
  
This will change the value of workspace.IsBatch to false if none of the items has this property, whereas the original code would not. This is inconsistent as workspace.IsBatch may have already been true due to some previous code, so making this modification introduces a bug. If you want to make this further simplification, the following is needed:
  
workspace.IsBatch = workspace.IsBatch || queue.Has(w =&gt; w.IsBatch);
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment14</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment14</guid><pubDate>Tue, 30 Sep 2008 17:29:37 GMT</pubDate></item><item><title>sheraz commented on Common issues found in code review</title><description>@Markus Zywitza: IList gives more flexibility as you are working against the abstraction. If you need the functionality of list then simply do this
  
  
public void Test(IList
&lt;string list)
  
        {
  
            string[] array = new List
&lt;string(list).ToArray();
  
        }
&gt;</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment13</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment13</guid><pubDate>Tue, 30 Sep 2008 16:39:31 GMT</pubDate></item><item><title>J.P. Hamilton commented on Common issues found in code review</title><description>The world would be a much better place if people would just read Refactoring. I have recommended the book over and over to people on my team. More than a year has passed and not one of them has read it. 
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment12</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment12</guid><pubDate>Tue, 30 Sep 2008 14:30:46 GMT</pubDate></item><item><title>Bryan commented on Common issues found in code review</title><description>I like having ILists as parameters to methods and return Lists from methods.  
  
  
A lot of the changes posted take &lt; 10 seconds with Resharper.  Also, I have never found (but Resharper always suggests) 
  
  
if(!someCondition)
  
{
  
     continue;
  
}
  
more code 
  
  
to be more readable than
  
  
if(someCondition)
  
{
  
     more code
  
}
  
  
I dont find nesting to be an issue unless we are talking about 3 or 4 nests inside eachother.  The logic one has to run through when considering the first option is going to slow down someone skimming code when looking over the 'continue' example as opposed  to the other statement.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment11</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment11</guid><pubDate>Tue, 30 Sep 2008 12:36:13 GMT</pubDate></item><item><title>Markus Zywitza commented on Common issues found in code review</title><description>I'm not keen on replacing List
&lt;t with IList
&lt;t. If it's a list, I can do some nice things like l.ToArray() or l.AsReadOnly(), which is not possible with IList
&lt;t.
&gt;</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment10</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment10</guid><pubDate>Tue, 30 Sep 2008 09:51:12 GMT</pubDate></item><item><title>Rik Hemsley commented on Common issues found in code review</title><description>Golf...
  
  
workspace.IsBatch = queue.Has(w =&gt; w.IsBatch);
  
  
On the subject of reducing nesting: I'm also a fan of the 'get me out of here' checks before the actual logic, but I think it's a shame that C# doesn't help us make these clearer.
  
  
In C#, I write code like this:
  
  
if (some condition)
  
{
  
    return;
  
}
  
  
if (! some other condition)
  
{
  
    return;
  
}
  
  
This can be 'tidied' to:
  
  
if (some condition) return;
  
if (! some other condition) return;
  
  
But this puts the returns at different levels, which isn't particularly readable and would probably cause me pain later.
  
  
Ruby allows this:
  
  
return if (some condition)
  
return unless (some other condition)
  
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment9</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment9</guid><pubDate>Tue, 30 Sep 2008 08:06:47 GMT</pubDate></item><item><title>Arild commented on Common issues found in code review</title><description>&gt; If you haven't added and refuse to add the extremely useful Has extension method, then you could use the less clear alternative:
  
&gt;if(queue.FirstOrDefault(w =&gt; w.IsBatch) != null)
  
&gt;workspace.IsBatch = true;
  
  
if (queue.Any(w =&gt; w.IsBatch))
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment8</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment8</guid><pubDate>Tue, 30 Sep 2008 07:30:30 GMT</pubDate></item><item><title>Daniel Crabtree commented on Common issues found in code review</title><description>I agree with all these changes, particularly the last guard clause example. 
  
  
However, the improvement made in the first case is marginal at best. Assuming you've implemented a Has extension method, there is a far better alternative.
  
  
if(queue.Has(w =&gt; w.IsBatch))
  
  workspace.IsBatch = true;
  
  
If you haven't added and refuse to add the extremely useful Has extension method, then you could use the less clear alternative:
  
if(queue.FirstOrDefault(w =&gt; w.IsBatch) != null)
  
  workspace.IsBatch = true;
  
  
Both replace the entire foreach loop and improve readability dramatically.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment7</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment7</guid><pubDate>Tue, 30 Sep 2008 06:30:02 GMT</pubDate></item><item><title>Ayende Rahien commented on Common issues found in code review</title><description>Phil,
  
Yes, I do find it more readable, and that is why I am doing it
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment6</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment6</guid><pubDate>Tue, 30 Sep 2008 06:09:45 GMT</pubDate></item><item><title>Hadi Hariri commented on Common issues found in code review</title><description>I just generally like "if" statements to have braces, even if they are only one line, because it's a source of bugs appearing otherwise (obviously "else" plays an important part here)
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment5</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment5</guid><pubDate>Tue, 30 Sep 2008 04:13:32 GMT</pubDate></item><item><title>Phil H commented on Common issues found in code review</title><description>On a semi-related topic, I noticed during one of your screencasts code  like this:
  
  if (myBoolValue == false)
  
      DoSomeThing();
  
rather than:
  
  if (!myBoolValue)
  
      DoSomeThing();
  
  
Any particular reason for that? Do you find it more readable?
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment4</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment4</guid><pubDate>Tue, 30 Sep 2008 03:54:38 GMT</pubDate></item><item><title>Skim commented on Common issues found in code review</title><description>I don't see the point of the first refactoring.
  
  
It looks less readable - It'd have worked better if LuceneWork had a method called "IsNotABatch" instead of "IsBatch"
  
  
Moreover, I consider that guard clauses should be usually used near start of method.  When you use guard clause within for loop, maybe the collection itself need to be populated differently instead of having to check and add guard clause within for loop.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment3</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment3</guid><pubDate>Tue, 30 Sep 2008 03:03:42 GMT</pubDate></item><item><title>Agus Suhanto commented on Common issues found in code review</title><description>Nice post Ayende! I found some of the works have been marked by ReSharper. Yes, with ReSharper we are warned of something that might be wrong.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment2</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment2</guid><pubDate>Tue, 30 Sep 2008 01:33:28 GMT</pubDate></item><item><title>PLamb commented on Common issues found in code review</title><description>Not so sure about the first one. Changing to a negative condition and adding a continue and all you got rid of is some braces. If I'd come across your version, I would have changed it back like the first one. I'm pretty much of the same opinion for the last one too. It's "normal" practice to have a code flow for != null; introducing the continue doesn't improve readability for me. I agree on the others though. Maybe I've been doing too much ruby lately.
</description><link>http://ayende.com/3618/common-issues-found-in-code-review#comment1</link><guid>http://ayende.com/3618/common-issues-found-in-code-review#comment1</guid><pubDate>Tue, 30 Sep 2008 00:29:52 GMT</pubDate></item></channel></rss>