Using Blazor and Code Highlight

Code highlight or syntax highlight is a feature that displays text as source code. It is using different fonts and colors, that matches with the syntactical meaning of the code constructs. For examples keywords such as public or if are colored blue, while method names such as Main() can be colored to green. Highlighting code on an HTML website is a relatively easy task if one is using an existing syntax highlighter.

Integrating an existing code highlighter with Blazor is a one step more complex though. In this post, I am going integrate a Blazor site with Prism, which is a lightweight extensible code highlighter.

Getting started

The first step with prism is to choose a theme, additional languages and plugins. Prism will generate a CSS file and a Javascript file, which can be downlaoded from their website. Both files then should be added to the wwwroot folder of the Blazor project.

Find out more


Using NDepend

In this post, I am going get started with a tool called NDepend. NDepend is a static analysis tool, for .net developers, which helps to understand different levels of dependencies in the code. It also provides code metrics, technical debt estimation etc, among many interesting features. I have been looking forward trying it, and in this post, I will have a first glance.

I have a chatbot application to help me with the public transportation waiting times. The core logic of this application has been moved to a class library, but it has been powering a Windows Mobile application, an ASP.Net Core website, a Service Fabric application and an Azure Functions app. Every time, I had hosted in a new platform, I had small change and refactorings on the API, though there should be a good amount of tech debt piled up. Let's see how NDepend can help me find these issues.

Getting Started

NDepend can be installed as a Visual Studio extension or as a standalone app. I have tried both versions. For iterative work, it is handy to have the tool installed as a VS extension, but otherwise, I prefer the standalone executable version of the tool. There is a free trial version and a licensed version as well.

Find out more


Finding Duplicate Integers

This post is a continuation of using Vectorization to achieve better performance. In this post I am going to look at the performance aspect of another 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 duplicated by overwriting another number. Create a method that receives the array as an input and returns the replaced number.For example having an input of [2,5,4,3,1,7,3] should return 3, as being the duplicate, as number 6 is being overwritten by another 3.

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

Find out more


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