Missing Number Performance Tests

In this post I am going to look at the performance aspect for one of the tipical programming exercises on interviews.

Task usually goes by this:

Given an array with integers from 1 to N. The order of the integers is unknown. One of the randomly chosen number is replaced with 0. Create a method that receives the array as an input and returns the replaced number.

I am not going into the details of edge cases, input validation, error handling, etc. This post purely checks the performance aspects of some of the possible solutions. I also assume that N = x * 8.

Find out more


Static Initialization

The way static fields are initialized has been changed across .net framework version. As the framework matured, static fields have become initialized more lazily.

Today I will show a quick comparison between .net472 and .netcoreapp3.0 focused on static field initialization. I will use the following application to demonstrate the issue.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Start");
        var test = new Test();
        test.DoWork();
        Console.WriteLine("Start work");
        test.DoWork2();
    }
}

public class Test
{
    private static readonly Logger logger = new Logger();
    public Test() => Console.WriteLine("TestCtr");
    public void DoWork() => Console.WriteLine("Working...");
    public void DoWork2()
    {
        Console.WriteLine("Working2...");
        logger.Log("Completing work");
    }
}

public class Logger
{
    public Logger() => Console.WriteLine("LoggerCtr");
    public void Log(string message) => Console.WriteLine(message);
}

As normally, someone using C# for a while you would expect static fields and class constructor (or static constructor) run and initialized before the first instance of a class being created and used. Now this is not entierly true, as we will see it in the following sections.

Find out more


An excellent TypeScript Book's review

I have read a book about TypeScript for the past few weeks: Advanced TypeScript Programming Projects

This is an excellent book to get hands on experience with TypeScript. The author takes your through a series of projects, to show how one could use TypeScript instead of regular JavaScript. The very first chapter points out the benefits and additional features of TypeScript, then in each chapter we see a practical usage of it.

Throughout the projects we will see excellent examples for using OO design patterns such as Visitor, Chain of Responsibility, etc. A good point that the author also explains the details and implementation of these patterns. The code examples are nicely structured following the Single Responsibility Principal. Because of the many small types used, having the source code of the projects available on GitHub comes very handy to browse the code quickly.

The book shows how TypeScript may work along the most popular web frameworks such as React, Angular, Bootstrap, Material Design, Vue, WebSockets and ASP.NET Core. Having that many technologies might be a bit overwhelming if seeing them in the first time. Although the book does not go into the very details of these technologies, it points for further readings. I definitely recommend this book for a reader who has a minimum web development experience already, but also wants to get involved with TypeScript.

Find out more


Null-coalescing Operator vs. Equals - Equals

I have been asked the following question over-and-over: which solution is the faster and better to use in the condition part of the if keyword, to branch based on a property which might be defined on a nullable reference type:

  • to use the null-coalescing operator (??)

  • or the equals operator (==)

To give some context let's assume that we branch our code based on a reference type's bool property:

public class SomeClass
{
    public bool Condition { get; set; }
}

Find out more


Generating image to IoT DevKit with Azure Durable Functions

I have recently bought an IoT DevKit AZ3166, and playing with it a lot. First, it is a lot of fun. Secondly, it has a good documentation and project catalog to get started in no time. Thirdly, do not try to upload code to the device through and RDP session, that just does not work.

This post will show how I generate a graph in a Durable Function and display it on the IoT DevKit.

Device

Getting Started with IoT DevKit

Find out more