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


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]

NDC London: talks

Last three days of NDC London presented a constant paradox of choice, since every hour 7-8 speakers would have parallel sessions in different rooms. How the hell am I supposed to pick only one, if all of them are great? How on earth can you choose between Jon Skeet and Mark Seeman? My way of solving this problem was to spend an hour every evening going through the list of the next day’s speakers and googling their talks from the past. Sometimes this helped me to pick a brilliant talk from someone I had not known yet, sometimes this meant I would go to the Bill Wagner’s talk and… well, more on that later.

Being an old-school geek, I still prefer to make notes on paper, so I have pretty good coverage of what I learned during these talks. Hopefully all the recorded sessions will be available on the web soon (that’s the part I really like about NDC), but before this happens, here’s a list of my observations and learnings from the talks I personally attended.

[Read More]

NDC London: ASP.NET Core workshop

Apparently last year I was a good boy, because Santa has already made several of my dreams come true in 2017. This week I am visiting London and attending NDC London, one of the greatest and most inspiring conferences I am aware of. Until now I only knew it by watching numerous recorded talks from the past and listetning to these top notch developers on .NET Rocks. Well, this morning I was in an elevator with Scott Allen, whose courses on PluralSight were the major part of my learning materials on ASP.NET some years ago. And when I stepped out of this elevator, first thing I heard was “Hi, I’m Richard Campbell” (that’s exactly 50% of .NET Rocks I just met). I know, it sounds silly, but I actually feel like a little boy meeting his all time football idol or somebody like that.

[Read More]