In the beginning I was sceptical about AI capabilities on writing good code. I remember criticising others claiming such “ridiculous” things. Until I tried out seriously…
It’s commonly known that AI answers are as good as the prompts. So I started experimenting with “prompt engineering”. A new wierd term, I know but it has it’s right to exist. You might also know that I started integrating AI into my workflow for my C# projects. The more time I invest, it becomes better and my output becomes increasingly more productive.
In this article I tell you the practical usecases that I use myself to triple my useful coding outout each day. Useful meaning only code which handles code, I’m not even counting models classes, DTOs, interfaces, etc.
Client Logic Generation from HTTP API Documentation
The days of hours long API documentation transcribing into functional client logic are gone. AI now interprets and synthesizes this information, swiftly generating the groundwork for client-side operations. It’s a time-saver which proved to be perfect for making quick PoCs on my projects. I also optimized and refactored by using the same AI tool to reach production-ready quality.
Unit Test Generation
Testing code, a vital but often laborious task, has been revolutionized by AI. Let’s face it, we often don’t have time writing unit tests due to deadlines. Some of us really hate it, not seeing as productive as coding business logic, which is understandable. AI formulates comprehensive unit tests, covering various scenarios and edge cases, ensuring reliability without the traditional time investment. I advise you to gather all cases and then feed each desired input-output pairs. Don’t forget, answers are as good as prompts. You are the engineer instructing a “robot”.
Commit Message Generation
I really love this, one of my favourites. Especially when I modify a lot of code and it’s hard to gather all changes into a single commit message. There are many tools which give your customization over your commit message style. I combine two of them: one for commit title and the one for detailed description that covers features, bugfixes and optimization. Just search for “AI Commit Generator” or “GPT Commit Generator” in VS marketplace or in VS Code Extensions.
Performance Optimization
Who doesn’t like writing optimized code? But often we struggle with time concerns here too.
You can instruct AI to review and optimize your code for memory usage. It will suggest you to use more efficient data structures, caching and it also can implement them after you feed your source code to it.
For my DeclaroDotNet project, AI helped by suggesting and implementing caching types used by reflection. The improvement so good, DeclaroDotNet even beats Refit.
DeclaroDotNet: https://github.com/Lionence/Declaro.Net
More info and performance results: https://medium.com/@dev.nagydani/declarative-http-messaging-in-c-a22066f78a96
Mass Auto-Modification of Code Files
In a dynamic development environment, code continuously evolves. AI tracks my manual modifications, swiftly applying similar changes across the codebase to maintain consistency and eliminate redundancies, reducing manual effort and ensuring code uniformity. I use it to reduce the warnings in my code. I fix it in one place and then just feed all the other occurances to AI. Easy.
Local Code Review and Best Practice Application
Before any code reaches the collaborative stage, AI conducts a thorough review, providing insights and suggestions for improvement. Additionally, it automatically applies industry best practices, ensuring adherence to coding standards and enhancing code quality.
One example was when I asked AI to intoduce constants to Attributes on controllers and function definitions. I admit, I made a mistake by creating them in the same file as the code. The AI corrected me by putting it in a separate file, tho I didn’t asked.
Automated Class and Interface Generation
Parsing documentation to create classes and interfaces was a meticulous task prone to errors. AI now swiftly generates these structures, incorporating serialization attributes based on XML or JSON documentation, saving invaluable time and minimizing human error.
For me it was very painful going through Unas API documentation and reading all their DTO. Some of them having over a 100 properties… So I got pretty fed up quickly and turned to AI to fix the problem.
The API documentation reference, so you understand the pain I’m talking about: https://unas.hu/tudastar/api/termekek-adatszerkezet
OK, but which AI should you use?
This all can be achieved by GPT. I started to use ChatGPT to copy-paste content at first, then moved to existing solutions. I feel your concerns about constantly whiching windows, copy-pasting code and the existing free tools are too basic. That’s why I started to making my own open source free Visual Studio Extension.
Until I bring that to good quality, I there are a few options that you can experiment with:
- ChatGPT, if you’re just a beginner
- OpenAI Platform API (or Azure OpenAI if it’s available for you)
- Free VS and VS Code extensions
- Paid extensions
- GitHub Copilot if you can get it
What’s next?
You are free to experiment or if you’re conious, follow me for more insights!
You can also contact me for more personal details about the upcoming release of my AI assistant extension for Visual Studio.
Follow and contact me on LinkedIn, share your ideas and pain points that you think AI can solve.
Stay tuned, keep being innovative! Happy coding!