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]

5 Ways To Manage Database Schema Changes in .NET

Most useful applications these days store some data in some storage. Sometimes this storage is a relational database with a well-defined schema. This schema might evolve with time, requiring production databases to be updated. In some cases, this is a rare occasion and perhaps can be done manually. However, if a company follows an agile approach and is trying to deliver new releases continuously, then these manual updates can quickly become too much of a headache even for experienced DBAs.

[Read More]

C# 7.0: Deconstruction demystified

Introduction

Let’s talk about one of the cool new features of C# 7.0 - deconstruction. Quite often you might need to return more than one value from a method, which can be accomplished in several ways:

  • use out/ref arguments (usually considered a code smell)
  • create a more meaningful class/struct that represents the result of calling the method (a preferable option, especially as the number of returned values grows)
  • use System.Tuple (some kind of a middleground)

They all work, but in fact only a special return type feels like a good solution, since both out arguments and explicitly used tuples look just like a boilerplate code and don’t contribute to readable code.

[Read More]

Abusing .NET Core CLI

When developing with .NET Core, you have two different workflows to choose from: manage projects from Visual Studio or work from a command-line using dotnet commands. New projects can be created this way, and after the recent updates the project templates system became extensible, allowing to install additional templates or even create your own.

[Read More]

Static site deployment options

I know that for a lot of people their blog is something that should just work. So they go for WordPress and focus on writing, especially when a blog happens to be a major source of income. Well, mine has zero commercial value and I also enjoy being a web developer, so I keep using the blog as a guinea pig for new ideas.

[Read More]