Hi and welcome👋.

I’m Phong.

On this blog, I write about topics related to my work.Why writing? Because writing helps me think - there is no better tool for organizing a long line of thought.

C++ - Chapter 12: Template

Template A C++ template is a mechanism for creating generic functions and classes that can operate on different data types without duplicating code. Template types are often called generic types T, and programming with templates is known as generic programming. A placeholder type T can be used for function parameters, return types, and local variables whose actual type will be determined later. A template parameter declaration template <typename T> defines the template parameters that can be used within the template. 1. Function Template A function template defines a family of functions. Syntax: ...

June 14, 2026 · 4 min · Phong Nguyen

C++ - Chapter 13: Concurrency

Concurrency Concurrency refers to the ability of a program to make progress on multiple tasks during the same period of time. On a single-core CPU, concurrency is typically achieved through context switching On a multi-core CPU, concurrent tasks may execute in parallel It’s used to improve the program performance and response time Concurrency in C++ can be implemented using several approach: STD Thread (C++11) Async/Future (C++11) Coroutines (C++20) 1. Thread-Based Concurrency 1.1. Threads A thread is the basic unit of execution within a process (multitasking.) ...

June 14, 2026 · 8 min · Phong Nguyen

C++ - Chapter 10: OOP

Object Oriented Programming Four Pillars of OOP in C++: Abstraction is the process of hiding the implementation details and only showing the essential details or features to the user. It allows to focus on what an object does rather than how it does it. It is achieved using abstract classes (classes that have at least one pure virtual function). Encapsulation is the process of bundling data and methods into a single unit (class) and restricting direct access to some components. Data is hidden and accessed through public methods. It is achieved using access specifiers like private, protected, and public. ...

June 13, 2026 · 17 min · Phong Nguyen

C++ - Chapter 11: Exception

Exceptions Exception handling provides a mechanism for separating error handling and other exceptional conditions from the normal execution flow of a program. Why We Prefer Using Exceptions They force the caller to recognize and handle error conditions instead of allowing the program to continue incorrectly or terminate unexpectedly. They allow errors to propagate up the call stack until they reach a layer with sufficient context to handle them properly. During stack unwinding, destructors for objects in scope are automatically called, helping prevent resource leaks. The exception mechanism introduces minimal performance overhead when no exception is thrown. When an exception is thrown, the cost of stack traversal and unwinding is generally comparable to the cost of several function calls. ...

June 13, 2026 · 3 min · Phong Nguyen

C++ - Chapter 7: Structuring Codebase

Structuring Codebase 1. Scope, Storage Duration A variable’s storage duration determines when it is created and destroyed. 1.1. Automatic Storage Duration Variables are created when execution reaches their definition and destroyed when their enclosing block exits. Includes: Local variables Function parameters 1.2. Static Storage Duration Variables are created when the program begins and destroyed when the program ends. Includes: Global variables Namespace variables Static local variables 1.3. Dynamic Storage Duration Variables are created and destroyed under programmer control. Includes: ...

June 13, 2026 · 7 min · Phong Nguyen

C++ - Chapter 8: Structures

Structures, Classes, Enumerations, and Unions In C++, struct, class, and union automatically create a new type name, so we don’t need to prefix variables with the keywords struct or union as in C. 1. Enumerations An enumeration (enum) is a user-defined type whose values are restricted to a set of named integral constants called enumerators. unscoped-enum: put their enumerator names into the same scope as the enumeration definition itself scoped-enum: keep their enumerators inside the enum’s own scope.Using enum class keyword. using enum <EnumName> statement imports all the enumerators from an enum into the current scope. enum color { red, green, }; // Scoped enum: enumerators are inside the enum's scope enum class shape { circle, square, }; // Scoped enum inside a namespace to prevents name pollution namespace game { enum class direction { up, down, left, }; } // Scoped enum with explicit base type enum class status : uint8_t { ok = 0, error = 1, }; 2. Union A union is a user-defined type whose members share the same memory location. ...

June 13, 2026 · 4 min · Phong Nguyen

C++ - Chapter 9: Class

Classes 1. Introduction A class is a user-defined blueprint used to create objects. It defines the properties and behaviors that all objects of that type share. An object is an instance of a class. It represents a real entity and contains actual values for the class’s attributes. An instance (instance) is a specific object created from a class. 2. Class Declaration 2.1. Class Syntax A class can contain: Data members (attributes) Member functions (methods) Constructors and destructors Nested types and other class members Declaration and Definition A declaration introduces a class name to the compiler A definition provides the complete class body. ...

June 13, 2026 · 17 min · Phong Nguyen

C++ - Chapter 1: Introduction

C++ Introduction 1. Introduction C++ was developed as an extension to C. It adds many few features to the C language, and tis perhaps best through of as a superset of C. How To Program Step 1: Define the problem I want to write a program that will … Step 2: Determine how to solve the problem Determine how we are going to solve the problem you came up with in step 1. ...

May 24, 2026 · 7 min · Phong Nguyen

C++ - Chapter 2: Fundamentals

C++ Fundamentals Basic Concepts Data is any information processed or stored by a computer. A Value is a specific piece of data (e.g. 42, 'A', 3.14). An Object is a region of storage (memory) with a type and a value. A Variable is a named object used to store data. Initialization is the process of giving an initial value to an object or variable. Literals: fixed values like 42, 3.14, ‘A’, “Hello”, true, nullptr. Operators: symbols that act on values (+ - * / %, == != < >, && || !, = += -=, etc.). An Expression is a combination of operators, constants and variables that evaluate to a value. A function is a reusable block of code that performs a specific task. 1. Initialization C++ provides several ways to initialize objects. Each form has different semantics and use cases. ...

May 24, 2026 · 9 min · Phong Nguyen

C++ - Chapter 3: String

C++ String 1. C-Style String A C-Style string is any null-terminated byte string (NTBS), where this is a sequence of nonzero bytes followed by a byte with zero (0) value (the terminating null character). terminating null character: '\0' length of an NTBS is the number of elements that precede the terminating null character. An empty NTBS has a length of zero. size of an NTBS is the size of the entire array, including the terminating null character. A single quotes (') are used to identify character literals. A double quotes ('') are used to identify string literals. String literals are stored in your program image, usually in a read-only section (.data), 1.1. Create a String /// @brief 1.Using pointer char* str1= "abc"; // sizeof(str1) = 32 or 64 (ptr) str1[0] = 1; // error, ptr to const /// @brief 1.Using array char str2[] = "abc"; // sizeof(str2) = 4 str2[1] = 'a'; // OK For str_1, the memory for the array is allocated on the stack at runtime. The compiler initializes it from the string literal. At runtime, the program memory copies the string literal into the array For str_2, only the address of the string literal is held on the stack, and there is no copying of string literal. 1.2. Character Null: \0, 0x00, NULL Carriage Return And New Line: \r\n Case switching: 'A' ^ ' ' & 'a' ^ ' ' Special: \\, Escape sequences: Name Symbol Meaning Alert \a Makes an alert, such as a beep Backspace \b Moves the cursor back one space Formfeed \f Moves the cursor to next logical page Newline \n Moves cursor to next line Carriage return \r Moves cursor to beginning of line Horizontal tab \t Prints a horizontal tab Vertical tab \v Prints a vertical tab Single quote \' Prints a single quote Double quote \" Prints a double quote Backslash \\ Prints a backslash Question mark \? Prints a question mark (no longer relevant) Octal number \{number} Translates into char represented by octal Hex number \x{number} Translates into char represented by hex number 1.3. C String Libraries Copying strings : strcpy, strncpy Concatenating strings: strcat, strncat Comparing strings: strcmp, strncmp Parsing strings: strtok, strcspn Length: strlen #include <stdio.h> #include <string.h> void main() { /// @brief Copying char src[] = "Hello"; char dst[20]; strcpy(dst, src); // copy full string // dst = "Hello" strncpy(dst, "World", 3); // copy only 3 chars dst[3] = '\0'; // ensure null-termination // dst = "Wor" /// @brief Concatenating strings char text[20] = "Hi"; strcat(text, " there"); // append full string // text = "Hi there" strncat(text, "!!!", 2); // append only 2 chars // text = "Hi there!!" /// @brief Comparing strings int r1 = strcmp("abc", "abc"); // r1 = 0 (equal) int r2 = strcmp("abc", "abd"); // r2 < 0 (abc < abd) int r3 = strncmp("abcdef", "abcxyz", 3); // r3 = 0 (first 3 chars equal) /// @brief Parsing strings char line[] = "A,B,C"; char* token = strtok(line, ","); // first token: "A" while (token != NULL) { printf("token: %s\n", token); token = strtok(NULL, ","); } // strcspn: find first occurrence of any chars in reject set char sample[] = "hello123world"; size_t pos = strcspn(sample, "0123456789"); // pos = 5 (first digit is at index 5) /// @brief Length size_t len = strlen("abc"); // len = 3 } 1.4. String/Numbers Conversion Integer to String: itoa() (non-standard) String to Double: atof() String to Double (with error checking): strtod() String to Long (with base + error checking): strtol() #include <stdio.h> #include <stdlib.h> // atof, strtod, strtol #include <string.h> // itoa (non-standard on some compilers) void main() { /// @brief Integer to String (itoa) char buf[32]; itoa(1234, buf, 10); // convert integer to string in base 10 // buf = "1234" itoa(255, buf, 16); // convert to hex // buf = "ff" /// @brief String to Double (atof) double d1 = atof("3.14159"); // d1 = 3.14159 double d2 = atof("12.5xyz"); // d2 = 12.5 (atof stops at non-numeric chars) /// @brief String to Double (strtod) char* end; double d3 = strtod("45.67abc", &end); // d3 = 45.67 // end -> "abc" /// @brief String to Long (strtol) long v1 = strtol("1234", NULL, 10); // v1 = 1234 (decimal) long v2 = strtol("FF", NULL, 16); // v2 = 255 (hex to decimal) char* end2; long v3 = strtol("100xyz", &end2, 10); // v3 = 100 // end2 -> "xyz" return 0; } 2. C++ String Strings are objects that represent sequences of characters. <string> ...

May 24, 2026 · 6 min · Phong Nguyen