Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know if having a guideline for short lambda's and delegates is really useful. However, have a guideline for having short functions. The methods I write are on average 6 or 7 lines long. Functions should hardly ever be 20 lines long. You should create the most readable code and if you follow <a href="http://rads.stackoverflow.com/amzn/click/0132350882" rel="nofollow noreferrer">Robert Martin's</a> or <a href="http://rads.stackoverflow.com/amzn/click/0735619670" rel="nofollow noreferrer">Steve McConnell's</a> advice, they tell you to keep functions short and also keep the inner part of loops as short of possible, favorably just a single method call.</p> <p>So you shouldn't write a for loop as follows:</p> <pre><code>for (int i = 0; i &lt; 100; i++) { // Potentially significant amounts of code } </code></pre> <p>but simply with a single method call inside the loop:</p> <pre><code>for (int i = 0; i &lt; 100; i++) { WellDescribedOperationOnElementI(i); } </code></pre> <p>With this in mind, while I in general agree with Jon Skeet’s answer, I don't see any reason why you shouldn't want his example to be written as:</p> <pre><code>Parallel.For(0, 100, i =&gt; { WellDescribedPartOfHeavyCalculation(i); }); </code></pre> <p>or</p> <pre><code>Parallel.For(0, 100, i =&gt; WellDescribedPartOfHeavyCalculation(i)); </code></pre> <p>or even:</p> <pre><code>Parallel.For(0, 100, WellDescribedPartOfHeavyCalculation); </code></pre> <p>Always go for the most readable code, and many times this means: short anonymous methods, and short lambda's, but most of all short -but well described- methods.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload