Apparently, the future was yesterday, so now I have to keep up. Since I had to write some code recently (a small converter that prepares data for demos), I decided to use Github Copilot. With all the controversy surrounding generative AI, I can surely say that's not the case with code generators.
I knew that I couldn't just describe the entire task, because artificial intelligence isn't that intelligent (that, or I'm just incapable of explaining things this complex), so I had to break it down first (next time I'll try to describe the task to Copilot so it can break it down for me).
Thanks to my recent love for functional programming, I could easily break it down into phases like this:
myData
.ChangeThis()
.ThenThat()
.DontForgetThis()
.AndAlittleBitofThat()
.AndDumpItToFile();
Since I was starting my work with Copilot, I used only the chat feature like a noob, only later did I use comments, so whatever I failed to achieve on this exercise, I blame on the chat!
I have written it method by method. Told Copilot what the method should be doing, what parameters it takes, and what is its return type (seriously, it’s easier to write the method definition), and allowed Copilot to fill it with working code. It worked like a charm!
In the future (meaning: now) the most important programming language will be English.
The challenge that made me realize that was when I had to describe how I wanted the mockup chart to look!
I couldn't just paste it in Copilot, right? (Although, I have not tried. Copilot, add that to todoist!). Thankfully, I have many friends at work who know how to describe that kind of chart (reverse-V-chart, if you’re curious).
The second challenge was to ask Copilot (in chat, would be fun to try and do that with comments) to rewrite a method and make it more generic. I had two very similar methods I wanted to merge, and I wondered whether Copilot would help. It suggested an interface for both classes used as parameters and… copy-pasted the remaining methods without introducing a single change 😉 After many fruitless attempts I gave up on Copilot to do this for me.
I complain a lot here, but I was satisfied with most of the work Copilot did for me, including generating a lot of mock names. However, next time I will not ask for names of ships from pop culture as it can end with Annihilator, Terror, or any names not suitable for a corporate demo. Next time, I will ask him to use character names from My Little Pony: Friendship is Magic 😉
One thing that I haven't found a solution for was unit tests. Learning how to write unit tests first, and code second was very hard, almost impossible for me until I realized how functional programming makes it easy, and how object-oriented programming actually makes it hard. Of course, one of Copilot's praised capabilities is writing unit tests based on your code, which means you need to make the methods first!
I will have to check how this feature will work when used on a stub of a method that only has a definition and throws a Not Implemented Exception! Worst case scenario? I will have to write unit tests manually! But it's worth it!
Takeaway!
AI is here to stay! Art might be a problematic part to use AI in, but code isn't! You have the chance to write code fast. As fast as your capability to describe what you need!
What AI won't do for you?
Verify it’s work! You need to do it, not only as a pseudo-QA but also to future-proof your code! With unit tests, manual tests, and so on.
Design your solution! I mean, it might do it for you, but you should do it anyway. Learn design patterns, code architecture, and best practices. Shit, learn how to draw diagrams - at some point, it might help as well.
The name Copilot was not chosen at random. Remember! You are the pilot! Be the pilot!
For future game developers, this can be a powerful ally! Don’t underestimate it.