Null checking, allocations and mass refactoring with ReSharper

Imagine any .NET codebase you have worked on. What would be the most common usage of if statement in this code? Given the notion of The Billion Dollar Mistake, I bet it is the null check. Reference types in .NET are allocated on the managed heap, so when an instance of such a type is assigned to a variable, this variable essentially points to an adress in this managed heap. The default value of such a variable is null, meaning that it points to nothing and can’t be dereferenced. For instance, if you write a method with a reference type argument, you can’t always predict how this method is going to be invoked and there is no guarantee that it won’t be a null value. To protect your code from an unexpected NullReferenceException, you would typically write something like this:

[Read More]

Coffee and Links #4

Happy New Year everyone and thank you for reading this blog!

I decided to slightly modify the format of this series, so that the posts have only 3-5 links, but carefully selected and more focused ones. Information overload isn’t a joke and trying to learn everything is often counterproductive (ask me how I know it), while picking your battles and practicing deep reading helps internalize things you read.

[Read More]