How many binaries do you need for a .NET project? How many is too many? Does it really matter? I’ll admit I have a strong aversion to the phenomenon which I’ve dubbed “binary explosion” — tens (or hundreds!) of tiny…
Disorderly fault injection
Fault injection is a commonly used testing technique to force the system under test into failure paths, allowing observation and evaluation of the system’s ability to tolerate and recover from errors. There are many fault injection tools available, such as…
Null objects, not values
The Null Object pattern is oft-cited but not-oft-enough used (in my experience). After all, which looks more elegant/maintainable/object-oriented? The difference is subtle but important. Not only do null checks go away in the Null Object world, but overall responsibilities become…
Interfaces: sync or async?
Given an extensible interface, how should one decide whether to define synchronous or asynchronous methods? (Note that in this case I mean interface in the general software engineering sense, so feel free to substitute base class, exported DLL function, function…
Exception contracts (or lack thereof)
Visual Studio’s Code Analysis for Managed Code (formerly known as FxCop) has warned for approximately a decade against using generic catch (Exception) blocks. Many strongly-worded articles and blogs have been written to explain the reasoning. Perhaps even more digital ink…
A loop is a responsibility
A lot has been written about the single responsibility principle over the years. Rather than rehash what many others have said better, I want to give a common example of how a seemingly innocuous control structure can subtly but surely…
EventHandler and asynchrony
Events in .NET are for the most part inherently synchronous multicast delegates. It is therefore no surprise that async and traditional EventHandler-based delegates do not mix. Today I’ll illustrate one design approach which I’ve used successfully to get around this…
From sync to async: file I/O
In the previous post, I described the basics of switching to async for network calls. Today I will discuss the same for file operations. Reading and writing To read and write files asynchronously, look no further than System.IO.FileStream. You must…
From sync to async: network I/O
Converting from a fully synchronous design to an asynchronous one can be quite an ordeal. Unlike other types of design changes which can be safely contained, going async necessarily touches essentially every module and function chain that deals with I/O.…
Problematic parameters
Parameterization can be a very good thing. It is an oft-employed antidote to unfortunate hard-coded values: Generic type parameters can transform truly type-independent code without boxing penalties or casting woes: Despite all their benefits, parameters also have penalties and pitfalls.…