Browse by Tags

All Tags » Design/Coding Guidance » .NET Development » C# (RSS)

Dependency Injection

Dependency Injection (DI) is a form of Inversion of Control where the instances that one class need are instantiated outside of the class an “injected” into it.  The most common injection is constructor injection.  This is called inversion of...

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

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

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

Evolving code over time

Given economics, time constraints, resource limitations, etc.; you can't write all the functionality for a given solution for a single release. Even if you weren't limited by these constraints, you're likely to get changing requirements as...

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

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

DataGridViewColumn.Frozen

DataGridViewColumn.Frozen is documented as "When a column is frozen, all the columns to its left (or to its right in right-to-left languages) are frozen as well." Which is nice until you think of the consequences. The consequences being that...

ITSWITCH #1: Answer

Last post I detailed some code that may or may not have something wrong in it.  If you thought InitializeOne and IntializeTwo are semantically identical (e.g. they differ only by performance), you'd be wrong. If you simply ran the code, you'd...

ITSWITCH: #1

A short pop quiz on design/coding in C#...

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

Entity Framework Petition of Vote of Non Confidence

I had intended to be happy simply being a signatory of ADO .NET Entity Framework Vote of No Confidence. But, there's people suggesting signatories of this petition are wackos or on the fringe. Do yourself a favour and read the petition . Read what...

Spaces or Tabs?

In this day and age it seems silly to get into a discussion about whether your companies coding guidelines should have a section mandating either spaces or tabs for indents. Tabs are clearly more flexible, but I really don't think it matters at all;...

Single-Entry, Single-Exit, Should It Still Be Applicable In Object-oriented Languages?

Before the modern high-level languages Edsger Dijkstra came up with "Structured Programming". This programming methodology relied on the programmer to form and enforce most of the structure of the program--manually keeping sub-structures and...

Performance Implications of try/catch/finally, Part Two

In a previous blog entry Performance Implications of try/catch/finally I outlined that the conventional wisdom that there are no performance implications to try blocks unless an exception is thrown is false. I have some clarifications and details to add...

Performance Implications of try/catch/finally

The accepted wisdom regarding performance of try / catch | finally in C# has normally been: try has no performance side-effects unless an exception is thrown. A discussion I was involved in recently caused me to discover some performance implications...

Accumulative Construction

A while back someone asked for guidance on what order should polymorphic construction occur in C# classes. I guess I had never really put much thought into it before and have never seen other guidance on the topic; but, I can see where this can become...