As a software engineer, I’m always on the lookout for tools and technologies which can enhance my coding experience. When it comes to AI, we can either embrace it or get left behind. I choose the former. I have been using GitHub Co-Pilot for a few months now while developing a new project at work. This experience has given me valuable insights by allowing me to test the tool with a variety of tasks and different packages. In this blog post I will introduce GitHub Co-Pilot, highlight its benefits for Go developers, warn about potential issues, and provide my wish list for future improvements.
Table Of Contents
What Is GitHub Co-Pilot?
GitHub Co-Pilot is an AI-powered coding assistant developed by GitHub in collaboration with OpenAI. It integrates into your IDE as a plugin and uses machine-learning algorithms to provide real-time auto-completion and code suggestions.
Co-Pilot trains its model on publicly available code, which allows for a thorough understanding of best practices and common coding patterns. In addition to this, the tool considers the context of not only the current file but also all open files and dependencies too.
The tool is also capable of making code suggestions from comments. e.g. // Add a new gin /hello endpoint which returns Hello World.
The language you use to describe what you want is crucial, but personally, I’ve had decent results. Although, they may not be as good if you’re writing in a language other than English.
As stated on the GitHub Co-Pilot website, Go is one of the top-performing languages for this tool alongside Python, JavaScript, and TypeScript. This is great news for the Go community, as we are able to take full advantage of this technology today.
My Experience
Now that I have explained what GitHub Co-Pilot is and how it works, let me share my personal experience with it. As I touched upon in the introduction, I have been working on a greenfield project at work for the last few months and have leveraged Co-Pilot from the start.
As I used the plugin more, my experience got better. Although there is a learning curve to integrate it into your workflow, it’s worth persisting. But I can assure you, it’s not all sunshine and rainbows.
The Good
I have been using the plugin in the GoLand IDE, and it is fair to say it has significantly improved my overall coding experience. To be honest, I miss it when working on my own laptop for personal projects. Co-Pilot regularly ‘reads my mind’ and the more code you write, the better Co-Pilot’s suggestions become.
I recall an occasion when I was writing unit tests for my Gin API handlers. I had written the unit tests for getting and creating an entity and then received a suggestion from Co-Pilot which contained all of the unit tests for the update handler. The best part was that they were all valid tests, I was blown away.
One use case I think will fly under the radar is auto-completing Go Doc comments for exported entities like structs or interfaces. Meaning, I am no longer burdened with this repetitive task. Thanks, Co-Pilot.
Sometimes you require a utility function and don’t want to Google or navigate to StackOverflow. This is when the ability to make code suggestions from comments comes in clutch. e.g. Write a function which takes an integer as a param and returns true if it is a Fibonacci number
. I have had great results doing these kinds of operations. StackOverflow has also been seeing a dramatic drop in traffic which could be related to this feature, but I would just be speculating.
The plugin receives regular updates and I make it a top priority to stay up to date with the latest features. This is not a technology you want to sleep on.
The Bad
Just like all AI-powered tools in 2023, GitHub Co-Pilot is far from perfect. There are occasions, the suggestions are absolutely ludicrous. This is more common in new files, but I’ve seen it happen in mature files too.
Often the comment suggestions for exported functions relate to the wrong function altogether. This requires you to give Co-Pilot a nudge by typing the start of the function name. The tool also sporadically suggests using functions on third-party packages which don’t even exist.
From time to time, you can encounter bloated suggestions too, which take up the whole screen. The full page suggestions keep appearing and you have to keep hitting escape to reject and declutter your screen.
Co-Pilot heavily relies on publicly available data. Therefore, the newer the package, the less data available. This leads to deprecated libraries being suggested. I experienced this first-hand, as the tool suggested the archived GoMock package, rather than the new one maintained by Uber. This leads us to the next section.
Word Of Caution
While GitHub Co-Pilot can be a useful coding companion, it’s important to exercise caution and not rely on it blindly. I personally find the tool has a success rate of 80%, but accepting suggestions without careful analysis could lead to silly mistakes and nasty bugs. You need to remain vigilant and not become complacent.
I believe junior software engineers should avoid GitHub Co-Pilot altogether. I think it is important to gain an understanding of programming and its principles before involving AI. It is key to understand what you want to achieve and let Co-Pilot assist you. I want to reiterate you should not use code which you do not understand.
I’ve seen developers online use GitHub Co-Pilot to write entire applications from comments. I would strongly advise against using this feature for anything other than writing small utility functions. It is a recipe for having a codebase which you do not understand and therefore do not know how to fix.
Feature Wish List
AI has made significant advancements in the past year, but we still have a long way to go. I would like to rant about potential features that I think would take GitHub Co-Pilot to the next level. These include:
- Suggestions based on the entire project and not just the currently open files.
- Suggestions on code optimisation, highlighting benefits and drawbacks.
- Suggest file and folder structure changes based on selected patterns e.g. Hexagonal Architecture.
I’m sure the reality of implementing these features will be much more difficult than it sounds. In 12 months, I will write another blog post on GitHub Co-Pilot and reference these features to see if any were implemented.
Conclusion
In conclusion, GitHub Co-Pilot is a wonderful introduction to the industry and is here to stay. The tool improves the general quality of life for engineers and speeds up development.
Programmers reportedly spend 70% of their time reading vs writing code. This implies that GitHub Co-Pilot may not be as effective as initially thought. However, I believe that even a 10% improvement in the remaining 30% coding time would be a valuable investment for any company.
Nevertheless, it’s important to note that while Co-Pilot is a powerful tool, it should be used as an assistant rather than a replacement for understanding and writing code yourself. For this reason, I think junior engineers should avoid AI-powered tools until they gain a deeper understanding of programming as a whole.
If you’re debating giving GitHub Co-Pilot a go, I would highly recommend it. Everybody gets a free 1-month trial, so why not give it a try?
If you have any questions or comments, please leave them below. Also, don’t forget to subscribe to our newsletter to receive more informative posts like this directly to your inbox.
If you found this article helpful, please share it with your friends and colleagues.
Thank you for reading!
Leave a Reply