What Re-Learning C Taught Me About the Code I Write Every Day

· 8 min read · Johnathan Alexander

Each weekend my younger brothers and I join a Discord call for our weekly game nights. Although the primary activity is gaming, a close second is arguing about whatever came across our social media feeds that week, “There’s no water on the moon”. “Which is better, slushees or sodas”. It’s all in good fun, and usually in the spirit of getting a rise out of each other. If they really want to rage-bait me they will throw a glorious hot take or say something incredibly wrong about technology. It truly befuddles me how my younger brothers use computers every day, install mods, connect to VPNs, swap out hard drives, and have no idea how they work. After another one of my rants, I caught myself. I use high-level languages every day and lean on abstractions I’ve never actually examined. I use HashMaps all the time. I describe variables as Tupperware containers. It’s a useful analogy for beginners. It’s also completely wrong about what’s happening.

So I picked up C and started from scratch.

Eight weeks later, I’m deep down the rabbit hole. I had used C before, but went about as deep as a kiddie pool. I think differently about software than I did before. Not because C is better. Because removing the abstractions forced me to confront every assumption I was quietly making.


The abstractions you love are hiding decisions you should be making

In most languages, declaring a variable is a one-liner. In python, it’s even simpler, you don’t even need to specify a type. The runtime handles memory allocation, the garbage collector handles cleanup, and you move on. That mental model — variable as container — works well enough at that layer.

In C, you make every one of those decisions yourself.

When you declare int x = 5 in C, you are placing four bytes on the call stack at a specific memory address. The variable doesn’t hold the value the way a container holds water. It is a name for a specific address. The value lives there. When you start working with pointers, you’re not doing anything exotic, you’re just making explicit what every other language is doing silently. int *p = &x gives you the address of those four bytes. *p dereferences it and goes to that address and reads what’s there. That distinction is why pass-by-value and pass-by-reference behave differently. It’s the reason your Python function that “modifies a list” actually works, while the one that “reassigns a variable” doesn’t. The language isn’t being inconsistent. I just didn’t know what was happening underneath.


You cannot start typing before you think. C will punish you for it.

Most of the time, I’ll start writing and let the problems surface. The language catches a lot of mistakes or hides common pitfalls. The IDE catches more. There’s little reason to optimize since most modern hardware is powerful enough to handle anything you throw at it, and if it can’t you can always offload the task to a server. By the time I’m running the code, the obvious errors are already gone.

C doesn’t work like that. The compiler lets a lot through. The runtime lets more through. You get segfaults with no stack trace, memory corruption that shows up three function calls later, and bugs that only appear under specific allocator behavior.

During one of my exercises, I was building a queue. The dequeue function worked fine in isolation. The program ran clean under clang. No warnings. No errors. However, I kept getting a bad memory access error when running the application in the VS Code Debugger. Since it was 4am, I was tempted to leave it. I mean nobody will care. No one will ever see this code. I almost left it. I’m glad I didn’t. I had made an assumption in my logic and it was silently causing issues.

The problem was in the dequeue logic. When removing the last node, I set head = NULL correctly but never nulled out tail. It kept pointing to the node I had just freed. Two bugs from one missing line:


c
// dequeue — before fix
Node *temp = head;
head = head->next;
free(temp);
// tail still points to freed memory

// next enqueue on an empty queue
tail->next = newNode; // writing to freed memory
tail = newNode;       // now tail is correct, but the damage is done

The fix was one check:


c
if (head == NULL) {
    tail = NULL;
}

That’s it. One rule — when the queue empties, null out both pointers. Closes both the use-after-free on tail->next and the stale pointer on the next enqueue. The dangerous part: ASAN didn’t catch it. The allocator hadn’t reclaimed that memory yet, so the reads and writes appeared to succeed. The program looked like it worked. clang running clean was the lie. The VS Code bad access error was the only honest signal.

In a higher-level language, that bug either doesn’t exist or gets surfaced immediately. In C, it quietly corrupts your program state and waits in the shadows like a little gremlin. You have to think through the full lifecycle of every pointer before you write the function. If you don’t, you’ll spend hours debugging and end up going to bed at 8am, for something that should have been caught at the design stage.


Working code beats clever code. Every time.

This sounds rather obvious, but it’s the poison pull developers will often swallow gleefully.

Brevity in software development is addictive and can be genuinely impressive. Concise logic, minimal lines, functions that do exactly one thing cleanly. That’s what good code looks like. It also gets you praise in a PR. The problem is that chasing brevity before correctness is backwards. A compact function with a subtle memory bug is not impressive code. It’s a time bomb.

I had a habit of writing the “smart” version first, conflating it with clean. Terse conditionals, functions filled with ternary operators, doing two things in one expression. C broke me of it. The more I tried to be clever, the harder it became to reason about what the code was actually doing. I started writing the obvious version — longer, more explicit, sometimes repetitive — getting it working, then cleaning it up. The cleanup pass is faster and safer when you know the logic is correct underneath.


c
// Trying to be clever
while ((node = dequeue(q)) && process(node));

// Obvious version first
while (!is_empty(q)) {
    Node *node = dequeue(q);
    process(node);
}

Both do the same thing. The second one is easier to debug, easier to extend, and the intent is immediately clear. Once it’s working, you can decide if the first version is worth it. Usually it isn’t.


The rules you skip are the ones that protect you

Single responsibility functions. Simple over clever. Data structures that match the pattern. These aren’t style preferences. They’re load-bearing.

In a garbage-collected language, a function that does five things is messy and hard to test. In C, it’s also dangerous. The more a function is doing, the harder it is to track ownership of every pointer it touches. Who allocated this memory? Who’s responsible for freeing it? If the answer isn’t obvious, you have a bug waiting to happen.

Data structure choice is even more consequential. An array gives you contiguous memory and O(1) random access. A linked list gives you O(1) insertion and deletion at known nodes but scatters your data across the heap. Traversing a linked list means following pointers to arbitrary memory locations. On a modern CPU with cache lines, that matters.

Before C, I would reach for whatever data structure fit the immediate need. Now I ask: what’s the access pattern? How often is this data being inserted versus read? What’s the size and is it known at compile time? That thinking has changed how I design systems at work — not because I’m writing C there, but because I’m thinking about what the language is actually doing on my behalf.


Curiosity is a skill. It atrophies.

At some point I stopped asking why things work and started accepting that they do. It’s efficient. It’s also how curiosity dies.

“That’s just how it works” is a fine answer when you’re moving fast. It’s a bad answer when you’re learning. It can leave concepts completely abstracted. It’s the difference between reciting facts and understanding them. The reason Python dictionaries maintain insertion order since 3.7 isn’t arbitrary. It’s an implementation detail that became a language guarantee because the underlying hash table redesign made it free. Knowing that changes how you use them. Not knowing it means you’re writing code based on assumptions you’ve never verified. C removed that option. Every line requires an answer to why. Why is this a pointer and not a value? Why am I using malloc here instead of a stack allocation? Why does this function take ownership of this memory and not that one? After eight weeks I leave every session feeling like I know less than I did going in, and admittedly that is genuinely discouraging. But it also means my understanding is growing and I’m losing assumptions I didn’t know I had..

A lot of what I thought I understood about software was built on abstractions I never looked under. Some of those abstractions are good ones. They exist because the problem was solved and you don’t need to re-solve it. But you should still know what they’re doing.


So, what changed?

I’m more intentional about design before I write. I think about data lifecycle before I choose a structure. I default to the obvious implementation first and treat brevity as a second pass.

I read other people’s code differently now. I test differently. When I see a function that’s mutating state or managing a collection in Python or Javascript, I have a clearer picture of what’s happening underneath. The abstraction is still there, but it’s not opaque.

If you’ve been writing in high-level languages for a while and you’re starting to feel like you’re pattern-matching more than thinking — go write something in C. Not because C is the answer. Because the questions it forces you to ask are ones you should have been asking all along.

$ next --step

Shipping fast and not sure what's slipping through?

Thirty minutes, no pitch deck. Tell me how your team ships and I'll tell you where I'd look first.