Author image

Base Friend Design Pattern

Just a software design pattern I have come up with, as a means to effectively and efficiently share code between different components/classes without breaking (too much) the rule of encapsulation. For these reasons I will classify it as a behavioral design pattern.


We have a certain ResourceClass, that we wish to use its internals in various other UserClasses. How do we achieve interaction using the base friend pattern?

We can leverage the C++ friendship rules. We're aware that C++ friends break encapsulation, "friends invade our private life". We don't like that, we hate it. However.. remember that friendship is not inherited nor bidirectional. Given this we could create a base class for all our UserClasses and that class alone can be made a friend of the ResourceClass. Hence, that base class alone, call it BaseFriend, will have access to the ResourceClass....

Author image

Exception Class Hierarchies in C++

How to use exceptions, manage error codes in your C++ programs? That is the question of the day.

Luckily c++ exceptions are pretty standard in their programming. The strategy is to create a base exception class with a name of your choosing (KeyException was mine) and then you can create subclass exception classes, nested in the various principal classes of your codebase. For example, in a game engine project you can create GraphicsException, WindowException, KeyboardException all inherit from KeyException and override the getType and what() functions to provide meaningful unambiguous errors.

Let's start with a tiny C++ exception primer -reminder- though before you get your hands on the code.

You handle exceptions using a try block. 

Author image

Aspect Oriented Programming

Aspect Oriented Programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code without modifying the code itself, instead separately specifying which code is modified via a 'pointcut' specification, such as “log all function calls when the function's name begins with 'set'”. This allows secondary behaviors (eg logging) to be added to a program without cluttering the meaty code that's core to the functionality.


  • The AspectConfiguration specifies which aspect applies to which method of an object
  • Each aspect is essentially a method (or a separate class containing a group of those aspect-methods) written in an aspect-oriented language (or annotation, or through an idiom in an existing language).
  • Aspects are wrapped 'before', 'after' or 'around' methods. For example we...

Author image

Thread Pool

A thread pool is a software design pattern that helps programmers achieve concurrency in an optimal way. By maintaining a pool of threads ready to execute at any moment performance is increased since latency is minimized by keeping a set of threads always available; at the ready, instead of frequently starting them up and destroying them because of frequent brief tasks. Thus we avoid short lived threads which break concurrency.

All this because creating and destroying threads takes a longer time than keeping them constantly alive and waiting.


  • there is an array of threads - m_pool
  • there is a FIFO queue of tasks (a Task should be a wrapper for a Callable object) - m_tasks. Task are enqueue()ed into the task queue
  • all threads are started...

Author image

Event Queue, Message Bus and Dispatcher

NOTE: I will use the terms event and message interchangeably. In some contexts there may be a minor differentiation but for this discussion it will be ignored.

Event Queue or Message Bus


Decouple when a message or event is sent from when it is processed. - R. Nystrom

What's the easiest way to manage the connections between event listeners and event producers? You guessed it, “Event Queues”.

When an event occurs, such as user input, or an entity sending an event to another entity, it needs to be stored somewhere such that it's not lost while in transit between the source that reported the event and when the program gets around to respond to it. That “somewhere” is a queue.

New events are added (aka enqueue) to a queue of unprocessed events. And at a later time when it's convenient in the application we...

Author image

Console on a Windows GUI Application

Provision Windows C++ GUI applications with a fully featured & functional console window that you can use for logging or whatever other purpose you deem would prove useful.

I used Windows 8.1 x86_64, Visual Studio 2017 & C++17 to build the project.


Github repository link.

Author image

C++ Timing

A Timer that I plan to use in a lot of projects.

Bonus: Performance log - merely an extension of the Timer entries, which is actually an array of pair<timestamp,stringLabel>. It has many uses. Find one!

Plenty of test cases to test thy mettle.

I used Windows 8.1 x86_64, Visual Studio 2017 to build the project. It should work on other platforms as well.


Github repository link.

Author image

C++ Vector Implementation

A C++14/17 ready allocator_traits aware Vector similar to std::vector . I made it to familiarize myself with the internals of containers in the C++ standard library.


  • fix some obscure Iterator problems (perhaps add begin() and end() to it) - we'll see
  • shrinkToFit(#) : if current storage is larger than # Bytes, it shrinks it to # bytes
  • halfSize() shrink

I won't attempt to create a full tutorial on this, because LokiAstari has covered this in excruciating detail already - in a level I can't hope to match (check out acknowledgements section below). If you're overwhelmed with templated code check out this tutorial:

Author image

Neural Network Demo

Following a great tutorial from YouTube by Dave Miller : “Neural Net implementation in C++”. Nothing more to be said other than watch his tutorial. It was the best intro on Neural Networks I had ever seen. I present it here with source code in case anybody wants to save a bit of time or double check with my version. And you can let me know of any errors or improvements. Thank you.

I used Windows 8.1 x86_64, Visual Studio 2017.


Github repository link.


All credits go to Dave Miller's excellent introduction to Neural Networks. I simply implemented his example as I was following along.