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.

Design

  • 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.

It stands to reason for me to want to make a thread pool to test my understanding of various modern C++ features and multithreading, as well as have it adorn various other projects that could certainly benefit from its features.

Design

  • there is an array of threads - m_pool
  • there is a FIFO queue of tasks (a Task should be a...

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

Definition:

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 to a queue of unprocessed events. And at a later time when it's convenient in the application we pull off the events from the...

Author image

Windows Console on a GUI Application


Provision Windows C++ GUI applications with a console for logging or whatever other purpose you choose.

I made this into a separate project because I intend to use it multiple times and others might get some value out of it as well.

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

Github

Github repository link.

Author image

C++ Timing


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

Bonus: Performance log - as an extension of the Timer, which is actually an array of pair<timestamp,stringLabel> and has many uses.

Plenty of test cases to test thy mettle.

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

Github

Github repository link.

Author image

C++ Vector Implementation


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

TODO:

  • fix some Iterator problems (perhaps add begin() and end() to it)
  • 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 others have done it better (check out acknowledgements section below). But the code is very well commented so you can read for yourself. If you're overwhelmed with templated code check out this tutorial: link.

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

Contribute

Please submit any bugs you...

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 have 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.

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

Github

Github repository link.

Acknowledgements

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

1