Browse by Tags

All Tags » Design/Coding Guidance » DevCenterPost (RSS)

IDisposable and Class Hierarchies

In my previous post , I showed how the Dispose Pattern is effectively obsolete. But, there’s one area that I didn’t really cover. What do you do when you want to create a class that implements IDisposable , doesn’t implement the Dispose...

The Dispose Pattern as an anti-pattern

When .NET first came out, the framework only had abstractions for what seemed like a handful of Windows features. Developers were required to write their own abstractions around the Windows features that did not have abstractions. Working with these features...

Thread synchronization of non-atomic invariants in .NET 4.5

Now that we’ve seen how a singular x86-x64 focus might affect how we can synchronize atomic invariants , let’s look at non-atomic invariants. While an atomic invariant really doesn’t need much in the way of guarding , non-atomic invariants often do. ...

If You’re Using “#if DEBUG”, You’re Doing it Wrong

I was going through some legacy code the other day, refactoring it all over the place and I ran into many blocks of code wrapped in “#if DEBUG”.  Of course, after a bit of refactoring in a RELEASE configuration these blocks of code were quickly out...

Testing Strategies Involving Async Functions

Some things to keep in mind when writing units tests for code that use async methods: You're not trying to test the framework's "awaitability" and you're not trying to test framework methods that are "awaitable". You want...

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...

Using the dynamic Keyword in C# to Improve Object Orientation – A Follow-up

Based on some feedback, some clarification is warranted with regard to my previous post titled “ Using the dynamic Keyword in C# to Improve Object Orientation ”. As Jarek Kowalski correctly pointed out, the example code that I provided could have used...

Using the dynamic Keyword in C# to Improve Object-Orientation

With polymorphism, object-oriented languages allow "...different data types to be handled using a uniform interface". Ad-hoc polymorphism is when you declare multiple methods of the same name but differ by the type of an argument. For example...

Becoming a Visual Studio Jedi Part 1

Becoming a Visual Studio 2008 (and often Visual Studio 2005) Jedi In much the same grain as James' Resharper Jedi posts, I'm beginning a series of posts on becoming a Visual Studio Jedi. It involves getting the most out of Visual Studio off-the...

Fundamentals of OOD Part 3: Method Cohesion

Single Responsibility Principle (SRP) helps us write more cohesive types and methods. Cohesion is the relatedness of the members of a type to each other and the relatedness parts of a method's code to other parts. Method cohesion Often times a method...

Fundamentals of OOD, Part 2 - Encapsulation Scope

Let's look at the ubiquitous Person concept. It might seem logical that an application that deals with people should have a Person interface for classes to implement. For example: public interface IPerson { String GivenName { get; set; } String SurName...

Fundamentals of Object-Oriented Design (OOD) Part 1

With increased usage of patterns and situationally specific strategies, people sometimes lose sight of the concepts and principles behind these patterns and strategies and fail to follow them when they're not using patterns or strategies. I feel it's...

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...