< Back

The Co-Pilot's seat: Harnessing GitHub Copilot for smarter coding

Author

Thomas Decock

Date

10/04/2024

Share this article

The era of artificial intelligence, more specifically large language models (LLM), is finally upon us. It has found its way onto our laptops in the form of a code assistant. There is a plethora of code assistants available right now for example: ChatGPT, Gemini, Devin, Amazon CodeWhisperer, Codium, Tabnine, etc. For this blog we’re going to focus on the most popular one at the moment named GitHub Copilot. Nearly 70 years after the first AI saw the light of day, it is now near impossible to think of what our lives would look like without AI surrounding us everywhere we go. From the phones in our pockets to now our code assistants in our integrated development environments (IDE).  

The question is no longer what the limits of AI are but rather what they should be.  

The same logic applies to programming. The question is no longer can AI solve this problem for me, but rather should I use AI for the problem I’m trying to tackle.  

I tend to always keep one simple sentence in mind when using AI and more specifically GitHub Copilot: “AI is not smarter than us”.  

Bold statement, I know, allow me to elaborate. What I mean by this is that you should always be the one in the driver seat when programming. Copilot is called ‘Copilot’ and not just ‘Pilot’ for a reason. The moment you let your code assistant generate code that you don’t fully understand, you’re no longer in control. At this point you’re no longer strengthening your coding skills but in fact weakening them. 

An AI user: The mayor of mount stupid 

Providing context to your statements is key when working with AI so allow me to do the same. 

Let’s say you’ve just graduated. During your studies you’ve discovered what GitHub Copilot can do for you and you got used to using it. You’ve managed to secure yourself your first job and you’re taking your first steps into development with your trusty AI by your side. You’re all excited for your first day on the job and it’s all smooth sailing. When suddenly the first major bug that you must fix arises. You try to tackle the problem head on and dive straight into it. About half a day later, digging through legacy code written by someone who’s not at the company anymore, you finally admit defeat.  

You just don’t know how to fix this issue, or what’s even causing it in the first place. But then it hits you, maybe you can just ask Copilot to ‘/fix’ this issue for you. You give Copilot the order and watch the magic unfold. You implement the suggestions the AI has given you, and the application is running smoother than ever before. The sense of accomplishment is immense. You managed to fix the issue and have therefore saved the day. 

A few days later you come across a new bug. This time they’re not going to fool you, you’re not wasting half a day bug fixing again. Let’s just ask GitHub Copilot straight away, that way you don’t have to spend time trying to figure out the issue. Instead, you can just focus on your one true passion developing new and innovative features. Bug fixed, new feature implemented, job done. You end the day on a high again. 

As time goes along and a million bugfixes later you come to the constatation that half of your code base has been generated by AI by now. You never really took the time to understand how the AI has been fixing all these bugs. You just trusted the suggestions as they always seemed to have fixed the problem up to that point. This time around your Copilot doesn’t know how to fix the problem though and the panic hits you. 

You’ve ended up in an endless cycle where you’re using AI, trying to fix bugs in code that was generated by AI in the first place. You come to the realization that all this time you’ve been reducing yourself into a copy-pasting machine with the occasional edit, without thinking about what you were doing.   

You take a good look around, and you realize that you’ve made it. You arrived at the top of mount stupid.  

Looking down into the valley of desp(ai)r 

As you wonder how you got here it becomes clear to you that along the way you lost your critical mindset. Instead of being sceptical about the code that was being generated, you depended on it. Despair settles in and you ask yourself, now what? How do I get out of this mess? Do I have to get rid of my AI altogether to become a better programmer? Is using a code assistant a bad idea in general? 

Of course not, AI can be a great companion along your programming journey if used correctly. To achieve this, I’ll list some things you should keep in the back of your mind when using GitHub Copilot. Of course, this list is non-exhaustive but rather a starting point. 

First of all, be sceptical. Always. Test all the code snippets that your code assistant generates for you. Preferably, by test automation. Make sure you have written sufficient unit tests during development and set up a testing framework to cover your end-to-end scenarios. This way you make sure that the code you have implemented does what you expected it to do, and you get a better understanding of how it works.  

Secondly, you should always assume the solution Copilot suggested is right for them, not for you. The same way StackOverflow usually gives you a solution to a problem, the answer provided is never the one you can implement without code adjustments. The answer will most likely, maybe, hopefully work for them but not for you. It does, however, provide you with a guideline to point you in the right direction. 

Lastly, referring to my original statement, Copilot is called Copilot for a reason. You are and should be the one in control at all times. You are the one who sets out the guidelines for Copilot. It will learn from your codebase and will base its code suggestions on your coding style. Keeping up the clean code principles will allow Copilot to implement those same standards and improve the quality of its suggestions. 

Walking the slope of enlightenment together 

Keeping these tips in mind, you pick yourself up again and start using AI again. Properly this time. As you start tackling new challenges at work you no longer solely depend on GitHub Copilot and a newfound sense of confidence hits you. Instead of asking Copilot to fix the issue all together you’ve put your finest Sherlock Holmes outfit on and found the underlaying problem. You used Copilot to assist you in writing a fix for the problem by using it as an IntelliSense on steroids. You were already re-writing the function you needed to adjust when Copilot suggested exactly what you had in mind. Tab, Tab, Poof, the problem is fixed. This time around you allowed Copilot to speed up the typing process whilst you were the one in control of how you were going to fix the issue.  

As time goes on and you’ve done some more research into how to use Copilot, or any other code assistant for that matter, correctly you’ve realized that an AI really does benefit from using the clean code principles. Your AI generates better suggestions ever since you’ve started using better function names. Descriptive names and clear context are like Copilot's secret sauce. The more context you provide (think " someDeclarativeVariableName" instead of "x"), the better Copilot can assist you. This virtuous cycle strengthens both your coding skills and Copilot's suggestions. 

Conclusion: A Symbiotic Relationship with AI 

GitHub Copilot is a powerful tool that can significantly boost your development workflow. However, it's important to remember that it's a co-pilot, not an autopilot. To use it effectively, you need a solid foundation in coding principles and a critical mindset. 

While Copilot can automate repetitive tasks and suggest solutions, it's crucial to understand the code it generates. Don't blindly trust its suggestions; always test and analyse them thoroughly. 

Think of Copilot as a mentor, not a magic bullet. The more you learn and improve your coding skills, the better Copilot can assist you. By working together, you can achieve a virtuous cycle of improvement, where both your coding skills and Copilot's suggestions become stronger. 

However, it's important to acknowledge that GitHub Copilot might not be the most suitable tool for junior developers. While it can help with boilerplate code and basic syntax, the lack of fundamental understanding can lead to reliance on AI-generated solutions without truly grasping the underlying concepts. This can hinder a junior developer's ability to learn and grow independently. 

Therefore, junior developers might benefit more from focusing on building a strong foundation in programming fundamentals before diving into AI-powered assistance. This will allow them to approach Copilot with a more critical eye and leverage its capabilities more effectively as they progress in their development journey.