Posts

Making Sense of std::variant in C++: An Introductory Perspective on Holding Different Types of Values

Image
The problem of variance in C++ variables that may take on multiple values of different data types is resolved using various mechanisms, such as std::variant , a new C++ feature in C++17. For this feature, a variable can possess a value of several types, but not more than one type at a time. In this article, welcome to the world of std::variant, and learn how it is used alongside some other useful elements like std::monostate which extend its capabilities. So let’s begin. What is std::variant? In C++, std::variant replaces the traditional union’ with a typesafe union holder which holds one of a predefined set of types. std::variantoffers the extra advantage of keeping the type that is currently held, unlikeunion’ which doesn’t keep track of its active type very handy in instances where a type will be constantly changing. suggested reads : CRTP in C++ , placement new  , memory management in C++ Declaring a Variant in C++ To declare a `std::variant`, specify the possible data type

Is Dead Code Really Dead?

Image
In today’s fast-paced environment of programming tools and new development techniques, developers are always on the lookout to ensure the codebases are neat and tidy as well as easy to maintain and extend. But one area of concern that is present in a number of projects is the presence of unnecessary code. This phrase may be familiar to you as well, but what exactly do you mean when you use the term dead code? More importantly, one may question: does dead code truly die, or does it continue to influence your software in ways that were not foreseen? This article explains the concept of dead code and its understanding, its effects on software application, and sound practices for programmers to follow not to allow such code within-keeping their codebase clean. What's a British term for 'it has been executed or needs out'? When applied to a software system, this “dead code” is code within a codebase that serves no purpose because it can’t be executed. This may include method

How To Visualize Clustered and Unclustered Index In SQL

Working with SQL databases forces you to come across primarily the clustered and the unclustered indexes. These are handy features that if used wisely can greatly enhance the speed of execution of the listed queries. But it can be hard to grasp their fundamentals, especially if you want to picture it in your head. In this blog post, I explain what clustered and unclustered indexes are, why they are of importance and most important how they can be explained without the necessity of explaining all the details. What is a Clustered Index? A clustered index specifies how the data stored in a table is sorted out in relation to the other fields in that table. Let’s consider, as an example, a to-do list that you create and find that it has automatically been arranged in a certain order. When you apply a clustered index on a unique key The control column such as SQL Server will automatically add rows of that table in accordance with the control column. Since the book-placement is done acc

How to Create Chain in Chain of Responsibility Design Pattern?

In modern software development, design patterns are important in structuring code and making it easy to maintain. One such design pattern is the Chain of Responsibility Design Pattern. Whether you're working with C++ or any other object-oriented language, the Chain of Responsibility (CoR) pattern offers a way to handle requests through a series of handlers, each capable of processing or passing the request along. In this article, we'll explore how to create a chain in the Chain of Responsibility Design Pattern, particularly focusing on C++ programming. We'll walk through an implementation, discuss how it works, and explain why it’s useful when flexible request-handling logic is needed. You might also want to read about Decorator Design Pattern . Designing Design Patterns with C#   What is the Chain of Responsibility Design Pattern? The Chain of Responsibility Design Pattern is a behavioral design pattern that allows an object to pass a request through a chain of poten

Introducing Materialize and Dematerialize Operators in C# Observable

  If you've been working with Reactive Extensions (Rx) in C for a while, you’re probably comfortable using operators like `Select`, `Where`, and `Subscribe`. But did you know that two lesser-known but incredibly useful operators give you deeper control over observables? Today, we're going to explore Materialize and Dematerialize. Don’t worry if they sound a bit scary—by the end of this post, you’ll see how these operators can make your life easy by debugging and handling errors much easier. Terms like Observable, Observer, and Subject are from the  Observer Design Pattern .   So, What Do Materialize and Dematerialize Even Do? Let’s start with Materialize. Normally, when you’re working with an observable, it emits data, completes, or throws an error. What Materialize does is convert all those events (values, errors, completions) into a `Notification<T>` object. It’s like converting each event into a form that you can inspect and manipulate.   On the other hand, Dem

Practical Example To Visualize Entities In Live Application Using MSAGL

Image
Finding it difficult to understand the complex relationship between the different objects which are part of an application? Think of Visualizing the objects and their state when the application is running, Seems exciting right?  Yes, It's possible with the little help from MSAGL(Microsoft Automatic Graph Layout) and some boilerplate code to do that. I have created a sample application demonstrating how it can be done, including the state of these objects in a live manner. I would recommend you to go through MSAGL Basics Check out the video here: Check out the code here: using Microsoft.Msagl.Drawing; using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace MSAGL_Demo { public interface INodeRepository { void AddNode(Node node); void OnActiveNodeChanged(string obj); } public class NodeRepository : INodeRepository { private IList<Node> nodes = new List<Node>(); private Graph g = null; public NodeReposito