Why are you caching data?

There are multiple reasons to cache data. For example, are you caching because of a performance issue of because of a correctness issue?  Know which, and comment it at the spot doing the cache.   If it’s performance, the idea is that you have some expensive operation, and you save the results so that you…

0

Why threading is hard

Anybody who says “I can write correct multi threaded code” probably should be saying “I don’t test my multi-threaded code”. It is very difficult to write correct multi-threaded code. One way to appreciate this is various “find-the-bug” pop quizzes that occasionally come up. Another approach that I’ll go after here is to look at the…

8

Simple Tool for text substitution plus Design questions

I wrote a simple C# app to do text substitution. It takes a (key,value) mapping and then replaces any keys in between {% … %} with their value. It’s a really trivial app. But it also quickly opens a Pandora’s box of design questions.   It takes an xml file that provides the (key,value) ,…

2

Making "Required properties" less annoying

Be wary of “required” properties that must be explicitly set correctly in order for the object to function (especially if it’s not obvious).  I recently got burned by this, and it’s certainly a frustrating problem to diagnose. In my case, the function didn’t give an error and just silently nop instead of doing the right…

2

Questions you should ask before using a callback / delegate

I just got burned by using callbacks in a multi-threaded app. I’ve rewritten the part to avoid callbacks, but for my good-deed-of-the-day, I wanted to issue a word of warning. Before you can safely use a callback / delegate / virtual function, particularly in multi-threaded code, you should answer the following questions: Do I hold…

5

How to start a console app in a new window, the parent's window, or no window

The ProcessStartInfo.CreateNoWindow property says “Gets or sets a value indicating whether to start the process in a new window.” and later “true to start the process without creating a new window to contain it; otherwise, false. The default is false”  But that’s misleading and wrong because it’s meaning changes depending on what another property (UseShellExecute)…

4

How can you force clients to use your APIs properly?

It’s tough to make a client use your API correctly. It’s especially tough to get clients to not do things that appear to work 90% of the time, but aren’t correct and break down in that remaining 10%.  It’s even harder for things that work 100% of the time in the current version but may…

2

An example of an API versioning problem.

Here’s an example of an API versioning problem. In general:Anytime you take two separate concepts and tie them together based off some current implementation assumption, you’re going to get trouble when that assumption is broken. The specific example:You currently (as of .NET 2.0) can’t unload the CLR once it’s loaded. The managed exit process debug…

4

Passing Property values by reference

I was wondering how well properties were integrated into C#.  For example, C# lets you use += with the properties.   It’s easy enough to convert:    MyProperty += 4to     MyProperty = MyProperty + 4 However, C# won’t let you pass a property in as a ref parameter.  For example:    void PassIntByRef(ref int x)    …    PassIntByRef(ref…

16

Design Implications from boring details

You can discern a lot of information about an API from what appear to be subtle or irrelevant details For example, each ICorDebug object has a logical parent. (See here for a brief explanation of the different ICorDebug interfaces). Here’s a chart: ICorDebugProcess ICorDebugThread ICorDebugChain ICorDebugFrame, ICorDebugILFrame, ICorDebugNativeFrame ICorDebugAppDomain ICorDebugAssembly ICorDebugModule ICorDebugClass ICorDebugFunction ICorDebugCode ICorDebugBreakpoint…

2