~/ $ noctrog


Recommendation: Kilo text editor tutorial

The past week I’ve been following the tutorial hosted here. It is a step by step guide on writing your own simple (< 1000 SLOC) text editor in C. Once I completed it, I felt a lot more comfortable handling strings, memory and interacting with the terminal without any external libraries. Although my code is nearly the same and I didn’t implement any new feature, I found that by reading the diffs, trying to understand them and coding what I remembered in my head was a good approach at retaining new information and techniques. Remember to comment your code, as it is impossible to recall everything.

This little journey wasn’t without bugs (in my code, the tutorials code was unpolluted). To catch the majority of them running cppcheck on the file was enough. For others a quick dig with GDB did the trick as the code is really simple.

As an immediate benefit, with the things I learned I was able to modify my fork of slstatus to display graphical bars to show cpu usage per thread (you can get my fork of slstatus here).

I really enjoyed writing software with C because of its simplicity and readability. Compared with C++, it takes considerably less mental effort to know what you are doing, and the compiler errors are not as cryptic. On the other hand, having to think of memory explicitly is a bit tiresome and error prone.