A good author writes better than a good developer

So here's a recent MSDN article that I actually had the chance of reviewing several months ago.  They've done a much better job at capturing the good new stuff in C# than I could ever do.

https://msdn.microsoft.com/vcsharp/default.aspx?pull=/msdnmag/issues/04/05/c20/default.aspx

I do still have a few personal corrections:

I commented that the internal names that the compiler generates have changed and will probably change again, and so the article should probably just mention that the name is compiler generated and not give the actual name (those that care can run ILDASM and see for themselves), but they didn't listen.  At least they did mention that is might change.  For those of you who have the community drop you'll notice that the compiler generated names have changed from what's in the article.

I also commented that using the binary tree wasn't exactly the best example of iterators because of it's miserable performance.  Yes it is clean and neat code, but if you have a binary tree with 5000 nodes and you foreach it a few times, you can watch your machine crawl as it is forced to spend more and more time in the GC rather than running your code.  At least they mentioned this potential problem (see the last paragraph before the Partial Types section).  Too bad my brain wasn't thinking and I got the numbers wrong.  It should state, “approximately n/2 iterator instantiations, where n is the number of nodes in the tree.”

Also note the small paragraph on #pragma warning that now gives you line-level control over individual warnings!

--Grant

Comments

  • Anonymous
    April 03, 2004
    I like this article too, but it has some glitches beyond the one you mention.

    Firstly, the author suggests that outer variables are copied into the fields of the anonymous method object when the delegate is created. This is not true; the outer variables are the fields of the anonymous method object from the start.

    Secondly, the example in Figure 10 does not show the full power of anonymous methods. A better version would be this:

    public class SafeLabel : Label {
    override public string Text {
    set {
    if (InvokeRequired)
    Invoke(delegate { base.Text = value; });
    else
    base.Text = value;
    }
    get {
    if (InvokeRequired) {
    string value = null;
    Invoke(delegate { value = base.Text; });
    return value;
    } else {
    return base.Text;
    }
    }
    }
    }

    Note that I use the very useful feature that outer variables are mutable.
  • Anonymous
    April 03, 2004
    The comment has been removed