[Project] What did I learn from building a text editor from scratch

2024-08-08

#projects #c

Introduction

It's been a long time since I've worked on a personal project. While browsing YouTube, I stumbled upon a video by @ThePrimeTime titled Projects that Every Programmer Should Try which immediately caught my attention. This video is a reaction to another popular video, and both recommend building a text editor as an essential project for programmers. Intrigued by the idea of creating an application that everyone uses daily, I decided to dive into this project and explore what makes it so interesting and challenging.

Planning

Initially, I felt a bit lost about how to start the project, so I began browsing for resources and guidance. Fortunately, I discovered a repository created by Paige, which provides a step-by-step tutorial for building a basic terminal text editor in C. This tutorial promises to cover all the crucial features within less than 1000 lines of code. However, I faced a significant challenge: I've never built a C program with more than two functions. I saw this project as a perfect opportunity to expand my understanding of this world-famous, yet notoriously challenging, programming language. Through this journey, I aimed to not only build a functional text editor but also deepen my knowledge of C and improve my coding skills.

It is a serious project

Text editor is something we use multiple times a day, maybe it's the reason I didn't think it will be too difficult. But that is one of my biggest miss-understanding in the entire decade. I need to think deeper, need to think about more basic behaviors such as how to handle key presses, how to quit the text editor etc. Therefore, following the tutorial helps a lot. By reading the doc I kept feel eye-opening,and repeatly said the same sentence: How can this genious know he need to build this feature. So I've learned a great lesson for my future projects that is I will need to do more research and try to make a conprehensive plan before I really start to build something. Those planning process will help me think through the project detailly and will help achieve what everyone wish to do: enhance productivity and avoid mistakes.

I don't really need all the fancy stuffs

The data structure I used and the code I wrote by following the tutorial are surprisingly simple. I wrote every line of code in a single file, used only built-in libraries, and stored all the text in a dynamic array of chars. We often seek out new tools or methods to solve our issues, but sometimes we already have everything we need to conquer the obstacles we face. I'm not saying we shouldn't learn new things and expand our knowledge base, but when the goal is to get the job done, it can be helpful to just dive in and get your hands dirty. Don't over-prepare and lose focus. Remember, we aim to complete the task, so let's get the job done instead of getting stuck in the planning stage.

Maybe I should not follow the tutorial

I can't count how many times I thanked the tutorial for helping me finish the text editor, but through writing this blog post and repeatedly reflecting on what I learned, I realized that I didn't grow as much as I had hoped in terms of coding a text editor or using C. These two aspects were my main goals for this project, but because the tutorial was well-documented, even though I read and understood every line, I still felt a bit empty. The gains weren't as significant as I had anticipated. I should have tried to do more on my own and experienced more failures during this project. I can almost guarantee that I would have grown more that way.