DEV Community

Cover image for How GitHub Copilot can WET your code (especially as a beginner)
Ádám Lőrincz
Ádám Lőrincz

Posted on

How GitHub Copilot can WET your code (especially as a beginner)

GitHub Copilot, (the controversial AI, that writes code instead of you) has been the subject of the discussion: "Will it deprive programmers of their job?". We cannot predict the future yet, but so far, it seems unlikely. In it's current state, it has the tendency to introduce bad coding habits.

Though, one thing is for sure: Copilot does an excellent job on lessening the time spent on Stackoverflow or looking up documentation. It is enabling us to write code faster. Not only we have access to code snippets from the web inside our IDE, but it can also find the "puzzle pieces" that are needed to be changed in the suggested code pieces, so we can apply the solution in our codebase.

Copilot reads our code as well as scraping the web and it will give personalised suggestions accordingly. For instance, if one has written their DAO's "create" method for a class in their specific way, Copilot will guess the create method for all the other classes based on their already existing implementation, but interchanging the right "puzzle pieces".

However GitHub Copilot is not (yet?) capable of suggesting method extraction, introducing interfaces or generalization.

This could lead to one overusing the automatic code generation instead of spending time with constructing a better, cleaner solution. This, however will often result in repeating code pieces. Why?

As said before, it writes the same code, but changes certain parts. This statement screams WET code.

Using these suggestions not only could make someone forget about considering writing cleaner code, but it also could appear much more convenient and sensible. Why?

For someone not using Copilot, WET code would have (amongst many) two huge disadvantages:

  • More typing, or lengthy adjustment of copied code (short term)
  • Chaos to maintain (long term)

Copilot makes it a breeze to write similar or worse, the same code N amount of times. This essentially eradicates the short term disadvantage of writing WET code. No retyping, no copy pasting and then changing parts of it, none of the similar hassle. It is all done via pressing tab once.

One could argue that experienced developers (hopefully) would not blindly rely on Copilot, hence there is no danger in using it with care. This statement is absolutely right. Beginner or careless coders, however might fall victim to agreeing with everything that Copilot suggests. Why wouldn't they? It's in the reach of pressing tab once and it (almost) always works. Thus, Copilot could give them the false perception of fast progress.

In the case of students, this is even strengthened by the fact that school projects often have tight deadlines, thus in many cases making clean code has to have a lot lower priority than working code.

Additionally, school projects have a limited length, where troubles with code maintenance may only appear near the hand-in date. At that point, students would say: "Okay, let's make this chaos work somehow, hand it in, forget about it."
Then, they would repeat the process... Each of their projects would progress exceptionally fast in the beginning, then as soon as code needs to be modified or extended, the rate of progress would drop drastically.

In conclusion, any coder who relies too much on Copilot could find themselves not exercising their knowledge of how to write not only working, but clean code.

It almost feels like the copilot promoted crappy WET over handwritten DRY. The point of DRY is to avoid repetitive code, not to write or generate it by AI.

...writes Pavel Movara, in the comments of Tapajyoti Bose's article.

Disclaimer: This is an article from a 2nd semester CS student and it is based on personal experience and limited research, take it merely as an advice.

Top comments (6)

nombrekeff profile image

Yup, I could see this becoming a problem. I've never been a fan of Copilot, I much rather use Tabnine, it learns from you and your team instead of the whole internet. It takes a while to start knowing your ways, but then it becomes quite useful. It's like autocomplete on steroids.

lukeshiru profile image
Luke Shiru

I've been using Copilot for a while and in my experience it adapts to your coding style and practices. Yesterday I wrote two functions and when I got to the third one, I just wrote the function name and Copilot suggested the rest with the same logic and style I would have used if I written it myself.

It uses the internet to learn "how to read and write code", but it uses your code, what you wrote, to make the suggestions (or at least, that's my experience).

ladam0203 profile image
Ádám Lőrincz

I just looked into it and seemingly it is only autocomplete so it doesn't generate e.g. whole methods by itself. Do I see it right? I think that would be a nice in-between between coding with just IntelliSense and Copilot.

nombrekeff profile image

Yup, correct. It's like the tipical autocomplete you get on common IDEs but it learns them from what you write on your projects, so it learns your style or the teams style. It only suggests stuff you normally write, not a jumbled mess created from the whole internet.

I really like this, it reduces the time you take to write code but it does not enforce or assume anything unlike Copilot.

Thread Thread
ladam0203 profile image
Ádám Lőrincz

Thank you for mentioning it, I might give it a shot!