Skip to Content

Porting a TypeScript Readability Library to Go with the Assistance of AI

This blog post details my experience porting a TypeScript readability library to Go, leveraging the capabilities of an AI code assistant (specifically, Cline, Claude 3.7 Sonnet). The project aimed to translate the functionality of the mizchi/readability library (a TypeScript implementation) to Go, ultimately aiming for a Go equivalent capable of similar text analysis and simplification. While the project isn't fully completed, the experience offers valuable insights into using AI for code generation and porting tasks. This process, while ultimately successful to a degree, highlighted both the strengths and limitations of using AI in software development.

The Project: Porting Readability to Go

My goal was to port the functionality of the mizchi/readability library to Go. This library provides text simplification capabilities, a task with clear practical applications in web scraping, content summarization, and accessibility improvements. While mozilla/readability exists as an established JavaScript implementation, I chose mizchi/readability as my starting point. The decision to use mizchi's version was based on several factors, although in hindsight, using the original mozilla library might have been more straightforward. Despite this, the experience of rewriting and reorganizing the code with AI assistance may have offered advantages in the porting process.

The choice of Go as the target language stems from several practical considerations. I'm proficient in Go, and its efficiency and low resource consumption make it well-suited for tasks like web crawling, which often rely on readability libraries. Furthermore, the project served as a testbed for exploring the capabilities and limitations of AI in code generation, specifically addressing the challenges of writing correct and efficient code from scratch using AI assistance.

Challenges and Approaches: AI-Assisted Code Generation

Employing AI for code generation presented unique challenges. While AI can quickly generate seemingly plausible code, the accuracy often suffers. Even with test-driven development or static typing (which Go boasts), the iterative cycle of writing, testing, and debugging consumes significant time and resources (in this case, API tokens for AI usage). The iterative process is time-consuming, even with the perceived speed advantage of AI-assisted coding. This highlights a critical difference between AI-generated code and human-written code: human developers often possess a more intuitive understanding of the underlying logic and best practices, allowing them to produce more reliable code initially.

However, AI's utility significantly improves when working within a well-defined context. Providing relevant context, such as official documentation or existing code examples, dramatically enhances the likelihood of generating correct code. This led to the creation of an "MCP" (Mechanism for Contextual Provisioning), a process to automatically provide AI with the relevant documentation and context. In this project, that involved cloning the external documentation (in this case the mozilla/readability codebase) and making it available to the AI assistant.

Methodology: Project Management and Tools

The project was managed using a combination of tools and methodologies. The project started with a clear plan outlined in TASKS.md, outlining the steps required for porting the library. A secondary file, MEMO.md, was used to jot down important notes and observations during development. The use of these files helped maintain a structured approach, which proved essential given the AI-assisted nature of the development.

Furthermore, the project leveraged the improvements in Go's tool management capabilities introduced in Go 1.24. While my AI assistant's knowledge base didn't yet include these improvements, the process of integrating and using these tools highlighted some of the complexities and nuances in software development that are not always readily apparent to an AI model. Even simple tasks such as installing and using external libraries can prove to be surprisingly complex, requiring careful consideration of dependencies, version compatibility, and environment setup.

The Role of AI: Strengths and Weaknesses

The AI played a pivotal role in the project, but it was not without limitations. The AI could generate significant amounts of code with minimal prompts, especially when provided with sufficient context. However, it often struggled with certain nuances in the Go language and its associated ecosystems, particularly those newer features or libraries that were not well-represented in its training data. This is particularly evident with the more recent Go features such as generics, which the AI demonstrated limited proficiency in using effectively. Older features, like the Go Context, posed less of a challenge, showing that the AI’s capabilities are intricately linked to the age and prevalence of specific language features.

Another crucial aspect is the overall "ownership" of the code. While AI assistance is valuable, the reliance on AI generation can lead to a decreased sense of ownership and understanding of the code. This can negatively impact long-term maintenance, debugging, and collaboration in open-source projects where code ownership is critical. The lack of deep understanding from solely relying on AI-generated code can hinder the ability to rapidly fix bugs or enhance the codebase over time.

Lessons Learned: AI in Software Development

This project provided valuable insights into using AI as a coding assistant. While it significantly accelerated the development process by automating certain aspects of coding and helping to overcome challenges through provision of relevant context, it underscored the limitations of relying solely on AI for software development. Human oversight remains critical for ensuring correctness, maintaining code quality, and fostering true understanding of the project. The process showed that using AI is not simply about replacing human developers; it’s about augmenting human capabilities, combining human intuition and problem-solving abilities with the AI’s capacity for rapid code generation and contextual awareness.

The cost of the project, approximately $30 over three days (with breaks included), reflects the efficiency gains offered by the AI assistant. However, this does not encompass the time spent planning, reviewing the AI-generated code, and debugging errors. This highlights the fact that even with AI assistance, there are substantial hidden costs involved in software development.

Future Implications: AI and Open-Source Software

The use of AI in open-source software development raises important questions about maintainability and sustainability. While AI can assist in rapid development, it’s vital to consider the long-term implications of relying on AI-generated code. The potential for issues like a lack of ownership, difficulties in debugging, and dependence on the continued availability of the AI tool could hinder the long-term success of an open-source project.

The project successfully demonstrated that AI can play a useful role in porting tasks, especially when dealing with code that is structurally similar across languages. However, for projects involving more significant design changes or complexities such as libraries that rely heavily on newer features or involve a large number of external dependencies, the use of AI may be more challenging. While AI can accelerate development, it is not a replacement for the expertise and critical thinking of a human developer. Careful planning, effective project management, and a clear understanding of AI's capabilities and limitations are crucial for successful integration of AI tools into the software development process. The ultimate balance will likely lie in a collaborative approach where humans and AI work together, leveraging the strengths of each to achieve optimal results.

The question of cost also plays a crucial role in the sustainability of AI-assisted development. The cost of API tokens, combined with the time spent in review and correction, needs to be considered carefully when deciding whether to incorporate AI assistance. This underscores the need to evaluate the cost-effectiveness and long-term sustainability of using AI in various software development contexts. Further research is needed to understand fully the implications of AI's growing role in shaping the future of software development, particularly in the realm of open-source projects where sustainability and community involvement are paramount.

Revolutionizing Sales Enablement with AI: From Static PDFs to Real-Time Coaching