-
C++ Type Casting
What is Type Casting? In software development, a “type cast” is an operation that converts an object to a different type. An example of this would be converting a variable of type int to double. Most object-oriented languages offer some form of type conversion or type casting, especially C++. This article will go over the…
-
C++ Strings
The string is a fundamental data type in many programming languages. In C++, a string is a data type that can store a sequence of characters. Despite being so ubiquitous and fundamental, strings are not primitive data types. To use a string in C++, you must include the <string> header from the standard template library…
-
Finding Closure: Rust’s Anonymous Functions
In software development, there exists the concept of functions. A function is generally defined by a signature, and that signature provides some defining information about the function, i.e., name, parameters, and return type. Functions are blocks of code that can be reused throughout a program through invocation. Simply call a function using its name, and…
-
Ghost in the Shell: PhantomData
Thu Rust compiler is notoriously strict, but this is not without good reason. Everything the Rust compiler does is to help guarantee type and memory safety so that (for the most part) the only bugs that can occur in a program’s runtime are logical in nature. Sometimes, the errors that the compiler throws may seem…
-
Examining Smart Pointers
Memory management is crucial to designing reliable and efficient software. Mismanaging memory can lead to buffer overflows, segmentation faults, and memory leaks. Sometimes, mismanaging memory can be gravely detrimental, leading to exploitable vulnerabilities that malicious actors can leverage as attack surfaces. Raw Pointers Pointers are variables that are used for tracking the memory address of…
-
The Observer Pattern
One of the fundamental software behavioral patterns discussed in the Gang of Four’s Design Patterns, the observer pattern is very useful for maintaining one-to-many relationships between objects. As such, it is typically implemented in OOP languages such as C++, Java, Rust, etc. This article will explore the motivation behind using the observer pattern, and an…
-
The Curiously Recurring Template Pattern
The Curiously Recurring Template Pattern (CRTP) is a C++ design pattern that exhibits some interesting behavior related to inheritance and polymorphism. It is considered an idiomatic design pattern, meaning it incorporates semantic design principles for efficiently implementing a recurring construct. In this instance, CRTP is heavily tied to C++ given the language features that C++…
-
The pImpl Pattern
Certain class implementations carry with them a lot of compile-time dependencies, and making changes to those will require recompilation of everything that uses a representation of the class. The pImpl (pointer to Implementation) pattern alleviates compile-time dependencies by moving all the implementation-level details of a class into a different class that is accessible via an…
-
The Singleton Pattern in C++
A singleton is a class that does not allow for dynamic instantiation. At runtime, one instance of the class is statically initialized, and this instance cannot be copied or assigned. To use the object, an accessor method is provided within the class definition to allow another portion of the program to grab a reference. Here…