Old project rewrite
Recently, I rewrote my 11-year-old project, Linux memory editor, with AI. Some people reject AI; some embrace it. I treat AI as the tool to do the task, but I know AI output is not 100% work. Nevertheless, AI has better knowledge than I do. But still, AI doesn’t have my specific knowledge, experience, and context; that’s why AI is just a complementary tool for humans to finish the task.
Memory editor
When I play games, I don’t like to spend time grinding (leveling up, collecting items, etc.). As a result, I use memory editing to make the gameplay faster. I created a Linux memory editor years ago. I started with GTK for the UI widget and used C++. However, GTK is less convenient for C++, so I switched to Qt. That’s how far it went.
And there is always a known deadlock bug that I cannot resolve. Adding a mutex doesn’t solve it either. The code is open source. I was really hoping that someone would join the project and work with me and possibly learn from each other and resolve the bug. But this never happened 😂.
AI era
Now, for me, AI is good news for software engineers. Firstly, as a programming language is a context-free language with context-free grammar (CFG), AI or LLM can work excellently in coding. Moreover, as LLM can process natural language well (natural language processing), this removes the barrier for humans to communicate with machines naturally. That’s how vibe coding emerged. Programming language is higher level than assembly language; now natural language is higher than programming language. We can use AI to write the code in various programming languages and build the product easily.
Secondly, AI or computers are systematic. It can analyze bugs and spot the issue better than a human, I mean at the code level. When a human writes the code, we may miss something, accidentally use the wrong variable, misunderstand the built-in functions, etc. These are not likely to happen with AI. That’s why AI-generated code or small functions usually don’t need exhaustive tests, because they will not likely be wrong. For example, asking AI to write a recursive function, if a human is not familiar with it, it may have infinite loops. But this can be simply avoided by AI.
How did I rewrite
I don’t subscribe to any AI chat because I don’t want to be vendor locked. If I subscribe to ChatGPT, surely I will fully utilize it; otherwise, it is not worth it. But that means I may miss the features provided by other AI service providers.
As a result, for the project rewrite, I primarily used Gemini CLI. CLI is needed because CLI agents can read the project files to have a better understanding of existing code. CLI agents can run the compilation and tests so that any error can be fixed automatically. Gemini is chosen because it is the only one that allows CLI to work on the free plan, but with quite a limited daily quota. That’s why I spent about 2 weeks working on the rewrite.
Before implementing Gemini, I need to do proper planning. To do this, I chose Claude instead of ChatGPT. ChatGPT is actually very good at planning, but recently it is very easy to hit the limit; this makes it hard to go deeper.
I provided Claude with some context, not source code-related. Then Claude suggested the new architecture. The problem is to be solved with execution serialization. That’s similar to Sidekiq queues from a Rails perspective. This will reduce the need for mutex. The more mutexes used, the more the design is flawed and debugging is a pain.
After I get the proposal from Claude, I put it into Markdown and ask Gemini to rewrite everything based on the old code and follow the new proposal. This is to be done in Plan mode to avoid unnecessary changes to the code.
The rewrite was done phase by phase. It takes days, due to Gemini being slow for my case, and it will hit the daily limit. But it is good enough to work on many tasks. During the rewrite, I need to verify what is working, what does not yet work, and if there are any bugs. That’s why it took so much time, but definitely faster than if I had rewritten everything from scratch.
Result
The final result is satisfying, and I don’t face any deadlock so far. Furthermore, the scanning is optimized because there are a lot of memory blocks that are unnecessary to be scanned.
With the limited time and limited knowledge, it is hard to maintain a project. With the AI, especially for software engineers, it really helps a lot to improve the code quality. LLM is really helpful in application development. But in my opinion, LLM may not work as expected when working on totally new things, such as writing in a new programming language and using a new algorithm, if it is not trained with these data.