RSSAmplifier

Blog

Lesley Lai's Blog

Lesley Lai's blog only feed

lesleylai.infoRSS feed ↗40 posts

Latest posts

A Love Letter to Flashcards

A personal reflection on how spaced repetition and hand crafted flashcards helps me to keep understanding alive

Fifty Shades of OOP

This post talks about the many different aspects under the umbrella term OOP

Self hosting comments with Comentario

A walkthrough of how I migrated my blog's comment system from the Commento cloud service to self-hosting with Comentario, Commento's active fork. I share my experience setting up Comentario with Docker, configuring a reverse proxy with Caddy, and customizing its client-side CSS. This post also includes reflections on the learning curve of self-hosting and notes on future plans to move away from…

Site Update (April 2025)

This post talks about me completely rebuilding this website, moving from Gatsby.js to Astro due to build issues and Gatsby's decline.

Representing an Abstract Syntax Tree in C++: Variants

This post explores various ways to implement an abstract syntax tree (AST) in C++. In particular, it focuses on representing "variant" structures that can hold values from a fixed set of alternatives.

Online Courses that I Recommend

In this post, I share a curated list of online courses that I found both enjoyable and insightful.

Small Naming Tip: Use "from" Instead of "to" in Function and Variable Names

This post offers a practical tip for naming variables and functions: use 'from' instead of 'to' to make code more intuitive and readable.

What happened to Lesley in the last couple of years

A cathartic post on what happened to Lesley as of 2023. It includes why I left college, what kept me from returning, and what my life has been like since.

Use ManuallyDrop in Rust to control drop order of structure fields

This post explains Rust's ManuallyDrop construct, and how it helps control the order of destructor calls.

CMAKE_SOURCE_DIR is probably not what you want

Today is the nth time I got bitten by CMAKE_SOURCE_DIR, so I will write it here. In short, there are two predefined variables in CMake: CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR. CMAKE_SOURCE_DIR refers to the top-level source directory that contains a CMakeLists.txt, while PROJECT_SOURCE_DIR refers t..

VK_KHR_dynamic_rendering tutorial

This tutorial shows how to use the VK_KHR_dynamic_rendering extension in Vulkan. It shows the steps required to load the extension, use it, and how it affects related components such as pipeline creation

How I create bilingual functionality of this blog in plain Typescript

This post explains how I implemented the bilingual functionality of this blog in plain Typescript.

Little C++ Standard Library Utility: std::align

This blog post explains C++ standard library's std::align utility, using an arena allocator as a motivating example

Fun with Ternary Search

This year is my first year doing the Advent of Code challenge, and today (2021 Day 7)‘s challenge is a fun one. I won’t go to the details, but the problem involves finding the minimum for a function. The function takes an integer and returns another integer. An interesting property of that function..

Don't automatically use auto parameters in C++

Since the advent of C++14, we can create lambda expressions that take auto parameters. And in C++20, we can even do the same thing for regular functions. With this feature’s advent, the programming style where all parameters are auto becomes popular among some C++ programmers. However, the feature i..

Using default parameters to circumvent the type system is an anti-pattern

I am doing some peer programming for a university course project today. In our codebase, we have a Ship class like the following: Later, the new requirement of the course project requires us to add another field, what we called captainsQuertersHealth, to the class, so we made the following change..

What is std::function in C++, and why do we need them?

Yesterday, someone in the #include discord server asked the following question: > how std::function works with lambda captures and functions handling I still don’t understand Below was my answer to the question, with some typo-fixes and expansions: INVOCABLES CAN HAVE DIFFERENT TYPES EVEN I..

Resources that help you to delve into C++

This post offers practical tips and curated resources for learning C++, tailored to different backgrounds and experience levels.

Factual errors in "These Modern Programming Languages Will Make You Suffer", and why it is a suffer to read

Today I stumble upon an article These Modern Programming Languages Will Make You Suffer after Twitter outrage. The post is absurd and indeed a suffer to read for me. However, it also receives 1k+ medium claps at the time of writing, and I cannot stay silent. In essence, this article tries to promot..

Improve Rust Link Time with lld

This post talks about the issue of slow link time in Rust and how to improve it by switching the default linker to lld - the LLVM linker.

Recursive Modules in OCaml

Recursive module is an interesting feature in OCaml. To use it, we need to use the form Explicit signature is required when using recursive modules, as the compiler can no longer deduce the module signature with recursion. A typical recursive module looks like the following: And we can even h..

Beware passing mutable lambda to STL algorithms

Passing complex mutable lambdas to C++ STL algorithms often leads to code that's hard to read and maintain. This article argues against treating 'no raw-loop' as dogma, and explores how using mutable lambdas undermine the benefits of . It also provides detailed case study on LeetCode's Two Sum and a predicate-based inner product.

The implication of const or reference member variables in C++

In the conventional wisdom of the C++ community, non-static const or reference data variables are considered problematic. Surprisingly, I cannot find a single resource dedicated to this topic. I decide to write this post because the same problem raises several time by different people on Twitter an..

Zero is the Devil: Common ways to construct bogus proofs

It is easy to make mistakes when conducting mathematical proofs. Nevertheless, you can find some recurring error patterns in those proofs. And some of the most common reasons are related to the innocuous-looking number zero. DIVISION-BY-ZERO FUN Let’s look at the following “proof” of : What is w..

The surprising codegen impact of noexcept

Would spamming the noexcept keyword make your C++ code faster? Sometimes. But not always. This post talks about the suprising downside when adding noexcept to functions.

Concepts in Programming Languages, Part II: Statics

What are the statics of a programming language? Most programming languages exhibit a phase distinction between static and dynamic phase of processing. People sometime loosey say static of a language happened at “compile-time,” and dynamic of a language occurred at “run-time.” The static phase of a l..

Concepts in Programming Languages, Part I: Judgements and Inference Rules

From a layperson’s perspective, the field of programming language research is full of jargon, greek letters, and weird symbols. On the one hand, Those common parlances make the programming language papers concise. On the other hand, you need not only mathematical maturity but also domain knowledge t..

Const Correctness Issue of std::function

The const type qualifier is one of the jewels of the C++ language design. Surrounding by this feature, we devise the “const correctness” practice to prevent const objects from getting mutated. The const correctness rule is straight-forward to follow for implementation of the most classes, but it is ..

Make Impossible State Unrepresentable, in C++

At CppCon 2019, I gave a lightning talk at called Make Impossible State Unrepresentable. Due to the nature of a 5 minutes lightning talk, it was handwavy, and I cut a lot of prepared contents to fit the time. This post is a deeper dive into the topic with more detailed explanations and examples. Th..

We are defining assignment operators wrong.

Update: Apparently there is a WG21 paper on this subject that goes in much more detailed than my post. I am surprised that I missed his CppCon talk on this topic and come into the silimar conclusion. One principle of C++ operator overloading is that the behavior of overloaded operators should be si..

CppCon 2019 Trip Report

What a week we had! CppCon 2019 is by far the best CppCon that I’ve ever attended. There are contents that interest me on every time slot, and for a lot of time there are conflict so that it is hard to decide which talk to go to. PRE AND POST-CONFERENCE CLASSES * Arthur O’Dwyer’s Standard Librar..

ACM Siggraph 2019 Trip Report

This year, several of the coworkers and I at Trimble SketchUp attended ACM Special Interest Group in Graphics (Siggraph) conference. It is my first time attending such a big gathering. The week is exciting, exhaustion, and also extremely rewarding for me. This year the conference location is Los ..

Intuition Behind X86 "lea" Instruction

During the last meeting of the North Denver C++ Meetup, some people mentioned that lea is more confusing than other instructions. lea is an acronym for “load effective address.” The usual explanation is “to put a memory address from the source into the destination.” The syntax of lea in the Intel Sy..

When does a C++ temporary object die?

A lot of operations of C++ require temporary values. Using them before their destruction is imperative. However, not all C++ programmers I met have a solid understanding of when a temporary expire. This situation often leads to over-conservative estimations, which will not cause any harm. Neverthele..

C++ Lambda Tutorial

C++ lambda expression is a construct added to C++ back in C++11, and it continues to evolve in each version of the C++ standard. A core part of the language nowadays, lambda expressions enable programmers to express anonymous functions and closures in C++. This post describes what a lambda expressio..

Book Review: "Functional Programming in C++"

Functional Programming in C++ by Ivan Čukić is a new book about applying functional programming principles in C++. This book is for people who already have a decent understanding of C++. It is written in an idiomatic style that a C++ programmer should feel welcome. If you just start to learn C++,..

Tail Recursion Explanation

Tail-recursion is an important concept to understand before we can analyse the behavior of a functional program. I will try to illustrate what tail recursion is with an Elm-like pseudocode. Though you don’t need to know any Elm to understand this post. FROM RECURSION TO TAIL-RECURSION Consider th..

Book Review: "Professional CMake: A Practical Guide"

CMake is the de facto industry standard for the build system generator of the C and C++ this days. Like C++, people seem to love and hate it at the same time. However, it is definitely a better choice compare to writting Makefiles manually. There are a bunch of Cmake resources online, in the forms ..

Resource management and RAII in C++

Recently, I have encountered a legacy code base at work. There are several tremendous class written like this: The real class is much bigger. We can criticize this snippet in multiple ways. For example, the copy-operations will do shallow copy, which is counter-intuitive. And programmers of the d..

Integrate a unit test framework in cmake

Automatic tests are ubiquitous in software industry these days. Especially to large-scale software, it is necessary to have a set of test to ensure the specification is fulfilled and to prevent regression bugs. In this post, I will not bore you with why we do test. Instead, if you are using the CMak..