Handmade Hero»Forums»Code
Burmi
4 posts
Compression-oriented Programming
Hello everybody!
I was finished the 27th Episode of HMH just recently and I wanted to read more about some stuff that was mentioned during the streams. And Also use the knowledge I gained through HMH in addition to all the good and bad stuff I learned beforehand aswell as all the failed engine attempts, to start creating the fundations of my own engine. To be precise I'm working on my own little Win32 layer.

There is a huge Problem I have with Casey's Plattformlayer. In a way it's unreadable for me and also I have problems remembering specifics. So in my own Plattform Layer I started to split the WinMain and Creating two functions: Win32_Initialize() and Win32_Shutdown(). These are responsible for Constructing and Destructing Parts of the Win32 Layer that are not specifically bounded to the Window, Stuff like Initializing DirectSound/DirectInput or the Game Memory.
Now what I thought about: Doesn't that break the Rule of Compression-oriented Programming (COP)?
And I'm going to reference Casey's own Definitions on mollyrocket.com, the Article "Working on The Witness, Part 11" under the Topic "Semantic Compression"
Here:

"Then, when I find myself doing the same thing a second time somewhere else, that is when I pull out the reusable portion and share it, effectively “compressing” the code."
That means, by pulling out the Initialization Code I have made it in a way "reusable"? Though I only did this with the intend of making it "readable" for me.

"Finally, the underlying assumption in all of this is, if you compress your code to a nice compact form, it is easy to read, because there’s a minimal amount of it..."
But if I use this lines It would mean that for me it made it more readable, because when I would go through code that I have written a longer time ago, I would go through it and say: "Oh there is the Initialization Function it does Initialization Stuff and The Shutdown Function does Shutdown Stuff". Therefore I can identify the structure of the WinMain faster, because the Win32 Thing is not polluted with Stuff that can be called as "Startup/Initialization Code". Which would make it easier to understand on an structural level, atleast for me.

I just wanted to ask this to be sure if I understood it correctly. And my change does not destroy the idea of COP.

Thanks :)
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Compression-oriented Programming
Deciding when to break things up for readability rather than reusability is always a bit of a difficult decision, because it is purely subjective. In general, I would say that it is probably the sort of thing that will vary from person to person. Some people may have an easier time with larger, straight-ahead functions, whereas others may have an easier time understanding smaller, single-purpose functions. There's always tradeoffs, and I don't think there's a "right answer" either way.

- Casey