Overusing the Null-Conditional Operator

The null-conditional operator is the ?. between object and field/property/method. It simply says that if the thing on the left hand side is null then the thing on the right hand side is not evaluated. It is a shorthand, so: if (a != null) { a.DoSomething(); } becomes a?.DoSomething(); And that’s great. It makes life […]

Parallel Loop Anti-pattern

Here’s a quick parallel loop anti-pattern. In other words, don’t do this, it will only make you miserable. If you want to start tasks in a loop watch out for including the loop variable as a closure to the task body. For example: Task[] tasks = new Task[20]; for (int i = 0; i < […]

Rant of the day: IDisposable

My colleagues are probably used to the fact that I rant about code quality frequently. I take code quality very seriously. Not because I’m especially expert in it, but because features of basic code quality make it easier for other people to read and maintain the code. Today’s irritation comes from some code (replicated in […]

The try-catch-ignore anti-pattern (again!)

I’ve blogged about this a few times, but today I just want to highlight the frustration this causes on fellow developers. Earlier today I saw a tweet from Chris Canal that said: “Are you swallowing exceptions there?! Hold on, let me get something to break your fingers with 😐” [^] All too often I’ve seen […]

The try-catch-return-false-throw-catch-return-false-throw-fail anti-pattern

I recently came across a wonderful anti-pattern. Well, anti-patterns are not wonderful, but the mind just boggles at the sheer bloody lunacy of this particular anti-pattern. I’m not going to show you the original code, but I’ll show a general representation of what it did: private void DoStuff() { if (!C()) throw new Exception(“The widget […]