2022/11/29

kilo

I recently went through the Build Your Own Text Editor tutorial. This booklet goes over building a simple terminal-based text editor in C. The editor itself has no dependencies (outside of the standard library) and is supposed to be decently portable. The editor itself is antirez's kilo.

I thought that the project was interesting and definitely provided a large amount of useful information. The most valuable aspect of these tutorials for me is seeing how someone else writes software. I'd read the description of a section and have a rough idea of what the implementation would look like; only to have the author do something different. Sometimes, I see patterns that I do not want to implement myself. Other times I find new ways of doing things that I will adopt myself. In traditional CS and programming education we spend the bulk of our time in the abstract. Being able to dive into concrete examples provides a different but still useful experience.

For this tutorial, I was surprised by the high-level architecture with respect to rendering. The core rendering code looks like it was pulled straight from a game engine, being written in an immediate mode style. This makes sense, given the context of this being a terminal application, but the similarity to game code was a surprise nonetheless. I also got to see a different approach to strings in C than I've seen before. I'll be looking to brush up on my memset skills thanks to this tutorial. I also gained some more appreciation for the curses libraries, given how difficult it is to interact with the terminal without them.

All-in-all, I'd recommend going through this tutorial. It was enjoyable throughout and has given me some ideas I want to play with some more. For languages like C, where there is no single "way", reading other people's code provides a valuable perspective.