Deep Dive on Closure Pitfalls

I’ve blogged about closures in C# and their pitfalls before.  I keep seeing problems with closures–more now that lambdas expressions and statements (“lambdas”) are becoming more widespread–even with experienced developers. So, I’d thought i’d post about some of the details surrounding where the C# compiler generates closures in the hopes that people will recognize more where they write code that creates a closure and its context. The C# language spec does not refer specifically to “closures”, with regard to capturing state for anonymous methods (including lambdas)–it refers to “outer variables” and “captured outer variables”.  The captured outer variables for a specific … Continue reading Deep Dive on Closure Pitfalls

DevTeach 2009 Vancouver

The schedule for DevTeach 2009 Vancouver has been announced (http://www.devteach.com/).  There’s lots of great software development sessions from some of the leaders in our industry. If you’re planning on improving yourself, this is the conference to go to.  Not only can you attend excellent sessions; but you can hob-knob with the presenters and pick their brains. If you have a friend or co-worker who’s interested, there’s a limited-time two-for-one offer for an even better price: http://www.devteach.com/Register.aspx

Nested Types

Recently Michael Features blogged about nested types.  The title was almost “nested types considered harmful”. I don’t agree.  I don’t agree that they’re any more harmful than any other C# construct (except goto…).  Nested types are like anything else in our tool-belt: they have a time and place and can be abused. But, when to use them?  Well, for the most part I agree with Michael, you should avoid them. But, there are times when they’re simply the best solution in a given set of circumstances. Let’s look at asynchronous programming model (APM) in .NET.         // Paraphrased from … Continue reading Nested Types

Resharper 4.0 EAP Settings and Installing Latest Build

The 4.0 EAP tends to do a full uninstall before installing (it’s pre-beta, pre-alpha even; so it’s no wonder). This tends to blow away your settings changes.  If that’s a pain point for you, the settings are stored in “%userprofile%\application data\jetbrains\resharper\v4.0\vs9.0”.  There are a couple of xml files in there that store your settings.  Before you upgrade to the latest build, just copy those to another directory.  It’s very likely that the format of these files has changed since the last build so copying the backups over the new version could possibly make Resharper to blow-up.  So, use with caution.

Upcoming C# 3 Guidance From Microsoft

Mircea Trofin has some design guidelines with regard to some C# 3 language additions (that I assume will make it into a revised Framework Design Guidelines of some sort).  They more less agree with the guidelines I published in Code Magazine a while ago.  There are some slight differences: Consider using extension methods in any of the following scenarios: to provide helper functionally relevant to every implementation of an interface… and, Do define extension methods in the same namespace as the extended type, if the type is an interface, and if the extension methods are meant to be used in most … Continue reading Upcoming C# 3 Guidance From Microsoft

New warning CS0809 in C# 3 (Visual Studio 2008)

There were several breaking changes (fixes) in C# 3 from C# 2.  One is the ability to attribute a member override with ObsoleteAttribute without also attributing it the virtual member in the base class. For example, the following will compile without error In C# 2 (Visual Studio 2005/.NET 2.0): using System; internal class BaseClass{    public virtual void Method()    {    }} internal class DerivedClass : BaseClass{    [Obsolete]    public override void Method()    {    }} public static class Progam{    public static void Main()    {        BaseClass baseClass = new DerivedClass();        baseClass.Method();    }} This same code will generate a CS0809 warning with C# 3. This change … Continue reading New warning CS0809 in C# 3 (Visual Studio 2008)

New Contributor to the C# Developer Centre

A new contributor to the C# Developer Centre has posted a new article.  This article goes into great detail about extension methods, what they are and how they’re implemented.  If you’re more than curious about this feature of the soon-to-be-release Visual Studio 2008 and C# 3.0, it’s a great read.  http://msdn2.microsoft.com/en-ca/vcsharp/bb905825.aspx