Valerius Petrini's

Programming Blog

I write about programming topics that interest me, like graphics, low-level systems, and web development.

Static Analysis in C: How to Use Clangd, Clang-Tidy & Cppcheck to Improve Your Codebase

#c#cmake#clang
by Valerius Petrini Jr. — 06/21/2026

If you've ever worked in a C codebase, you've probably been frustrated with the lack of tooling that is available to you, especially compared to more modern languages like TypeScript. The truth is, C does have capable tooling support, but they aren't as well-known as other tools are, and most don't come automatically out of the box. This article aims to show you how to set up three C tools to improve code quality and your editor experience: clangd, clang-tidy, and cppcheck.Read More

OpenGL Meets Calculus: The Math Behind Normal Maps

#c++#opengl#calculus#glsl
by Valerius Petrini Jr. — 08/18/2025

In `OpenGL`, you're bound to come across normals, which are vectors that define how light reflects off of an object. Normals are usually defined per-vertex or per-face in 3D models, but **normal maps** are used to simulate small details on surfaces by giving each *pixel* a normal vector. While normal maps are commonly used in graphics applications like `OpenGL`, the details behind how it works is often hidden behind shader logic that transforms the normal vectors from texture space to the coordinate space for lighting calculations. This article aims to explain what normals are, how they are calculated, and how normal maps are generated.Read More

CMake Made Simple: A Reusable Template for Your First C++ Project

#cmake#c++#ninja
by Valerius Petrini Jr. — 08/05/2025

When starting up a new `C++` project, you might run a command using your compiler like `g++ main.cpp -o main` to compile your program into an executable. However, as your project grows and includes more source files, libraries, and dependencies, managing compilation from the command line can become tedious and prone to errors.Read More

Building a Shell in C using fork and Process Management

#linux#c#shell
by Valerius Petrini Jr. — 06/29/2025

If you've ever wanted to build your own **shell** (the program that lets you interact with your operating system using commands like `git`, `ls`, or `node`) in Linux using C, you'll quickly come across the function `fork()`. In Linux, `fork()` is what allows a shell to create new processes for the commands you run. It's how shells can execute programs without freezing or crashing themselves, and it's the foundation of multitasking in Unix systems.Read More

How to Build a Compiler: A Step-by-Step Outline for Creating a custom compiler in C from scratch

#compilers#c#assembly
by Valerius Petrini Jr. — 06/10/2025

Over the past year I've been working on my own programming language, *Jakarta*, a compiled language that I needed to build a compiler for. If you're unfamiliar with compilers, think of them as the thing that converts your programming language's code (in this case `.jak` files) into machine code that your computer can then run.Read More