At the Palindrom, we do not just develop and mentor the AI based solutions, but using tons of existing tools in our daily job. I have been using AI coding tools for at least six months in my day-to-day tasks. In this blog post, I want to show a real-life example of how an AI engineer uses AI for coding in an existing project.
Problem: Challenges in Implementing a Book Sorting Feature with AI Assistance
In the BookStack application, a feature request was made to add a sorting option by popularity for the books view. Popularity would be measured by how often a book gets opened or loaded. This feature aims to improve user experience by allowing users to easily find the most accessed books, enhancing the utility of the application, especially for those managing large volumes of content. The challenge involved integrating this sorting functionality into both the frontend and backend systems while ensuring accurate data handling and efficient performance.
Original Feature Request: Sorting option “Popularity”
Used AI coding tools
Cursor Code Editor:
The Cursor code editor offers powerful features like the Ctrl+K editing mode, which allows developers to directly modify code with AI assistance. This mode leverages the current file context to provide relevant suggestions and presents a diff view for reviewing changes. Additionally, the Ctrl+Shift+L chat panel mode enables interactive AI conversations within the editor, helping developers debug, refactor, and understand their code more efficiently.
Codium AI:
Codium AI’s test generator UI streamlines test creation by automating the process. Initiating test generation through the UI opens an advanced panel that lists detected behaviours and generates corresponding tests. Developers can refine these tests, add new ones, and run them directly within their development environment. This ensures comprehensive test coverage and improves code reliability, significantly reducing the manual effort required for writing and maintaining tests.
Implementing the Popularity Sorting Feature with AI Tools
Understanding and Implementing Complex Features: The task required sorting books by various criteria such as name, creation date, and update date, and now by popularity. Implementing this feature involved both frontend display logic and backend data handling. I am not an experienced php developer. And the codebase is totally new to me. But the feature request references an existing feature, that is a good starting point to figure it out what I should do.
AI Approach: Using Cursor, I can ask how the “Popular books” section works on the webpage. (Please don’t forget to use the “with codebase” context, that makes AI search in the codebase itself instead generating a general answer.) Exploring the answer, I found a crucial function, called popularForList, that I could use the next prompt. A very effective method to guide the AI is showing examples. So when I asked, how I could implement the feature, I selected the popularForList function and I added to the chat with CTRL+SHIFT+L. It is a good example, how the view count is used in the codebase.
Generating Tests
Creating tests to ensure the sorting functionality worked correctly was another challenge.
AI Approach: Codium AI generated unit tests based on the described behaviour, covering sorting by name, creation date, and now popularity. Despite challenges like parsing HTML instead of JSON, AI tools were crucial in managing these complexities.
Integrating Tests and Handling Dependencies: But the problem is that the unit tests have a predefined test database. They are more like integration tests. Which is fine, I like the real-like looking tests. The generated tests by the Codium AI assumed they are totally independent unit tests.
AI Approach: Cursor helped me to debugging the issue and adding the proper php lines to get isolated tests. But I had to realize, the frontend uses different endpoint for the for sorting, than my book entity tests. AI coding tools or not, realizing this took too much time… It is what it is. I specified the prompt in Cursor to using the proper endpoint in the tests brought me the good direction.
I got some tests for sorting name, and creation time. These features were already implemented before my work, but they had no tests. So I added them. Codium AI is pretty useful, when you want to augment your existing tests. I think this feature of it that I use most of the time.
Final touch
The code analyser that is connected to the repository was not satisfied with the code I pushed. The method that I changed became too long. But I just copied the code analyser message after I selected the method and pasted into the CTRL+K edit mode. It wrote the necessary helper functions to decrease the length of the method.
Conclusion
This experiment demonstrates the significant benefits of AI tools like Cursor and Codium AI in software development. By automating repetitive tasks, generating context-specific suggestions, and assisting with test creation, these tools help developers focus on more complex and creative aspects of their projects. Embracing AI in your development workflow can lead to enhanced productivity, better code quality, and a more streamlined development process. As AI technology continues to evolve, its integration into software development will undoubtedly become even more indispensable. I leave here the pull request, if you want to see the final code that the AI wrote: https://github.com/BookStackApp/BookStack/pull/5132
References:
Member discussion: