Daily Recap - Day 09 Python and C Programming
June 18, 2025
Showing up
I should do more of these recaps everyday because I want to look back and see the learning process I went through to become a better programmer.
Some days are all about the grind, but there are going to be days where you don’t feel like doing anything. Today was a good example.
I had an hour or two free after work and really did not want to do much. But I opened a terminal and fired up vim. I said to myself, “if I can just write one line of code, even if it does nothing, I am still showing up.”
So I decided to just try to write a simple Python script that would print random quotes to the screen. BUT…
Learning Python (Again)
I had to find out which modules to import first. I had never written anything like this in Python, so I had to look up a bunch of things to get it working and fix a couple of spelling mistakes because apparently, I can’t type well…
I blame the keyboard. These cherry switches are so smooth.
But anyway…
After I got all that situated though, I looked at the clock and saw it had only taken me 25 minutes to get that far. A real script that entertains me and I still had time left over? Well what else should I do?
I though about how Python uses print()
to write a new line and remembered seeing that in a C program I wrote once upon a time.
Only C uses \n
to write on a new line. I don’t know why I though of that and compaired the two.
So anyway, I ended up trying to write a short program in C that would do the same thing. I had time to kill and wanted a deeper understanding of how my programs worked. Nothing better then programming closer to bare metal.
Diving Into C
It took me down a bit of a rabbit hole and I tried using libraries like <stdlib>
to get malloc and free to manually release the memory. Not that I had to, but because in my first C program I stored the string that I wanted to print out into static memory, which gets cleaned up after the program ends.
It looked like this:
const char *quote = "Max Kernel was here...";
Since it was cleaned up when the program ended, no malloc()
, no problem. I wanted to make things interesting so I tried using it to free the memory.
Malloc is basically this:
#include <stdlib.h> // Includes the library we need
int *numbers = malloc(10 * sizeof(int));
This just says: Hey OS, give me a block of memory big enough to hold 10 integers, and then give me a pointer to it! And do it NOW!
However, the memory that we want to allocate is uninitialized and probably contains garbage values from whatever was there before. Python has garbage collection which takes care of all that for us, but we are using C so we have to manually take out the trash.
Malloc(), Calloc(), and Free()
To do that we would use calloc()
which is the same as malloc()
but all bytes are zeroed out, which cleans the memory and lets us start fresh…
BUT, we still have to release this memory so we don’t get a memory leak. To do that we have to clean it up with free()
C assumes that you know what you are doing so you need to be careful.
So after I learned about calloc and why I should be using it, I wondered what the point of malloc was. I mean if you are going to use memory and want to make it clear before you use it calloc would be a better choice, right?
Well, not so much because you might want to use malloc when you do not know how much memory you need until runtime.
The user might input something that you were not expecting and you need to store that in memory. OR you want to allocate large data structures like maybe an array or linked lists.
Or maybe you just want control over the memory’s lifetime.
Whatever the case, if you are using malloc you could crash your program if you forget to clear the memory with free()
, confuse a pointer with a real variable or maybe forget to check if malloc()
returned NULL
.
But basically, C is a programming language that will let you do anything your heart desires, but only if you know what you are doing…
Why This Matters
So the main point of this article is not to show you what I did today, but to give you a glimpse of what is possible if you just sit down and open a text editor, and just start writing one line of code. Just to see where it goes.
You might end up writing garbage and not having free()
to come by and collect it. But you showed up.
Even when it was hard.
Even when you did not want to.
Even if you wrote garbage code and it did not work or you did not understand it.
The best thing you can do when learning any new skill is to just show up consistently.
That is all for today’s recap.
Stay curious.
And show up. Even if it’s garbage code.
Especially then.