Github Copilot and the DRY Principle

Ever A. OlanoEver A. Olano
2 min read

The answer is unfortunately the latter. I recently stumbled upon this article that talks about a study that found a correlation between Copilot-generated code and code churn. A lot of code is being reverted or updated within two weeks of their initial commit.

The article specifically mentions the introduction of duplicate code as one unfortunate trend.

I did experiment a little bit after reading it. I found that Copilot is able to reuse an existing method within the same class. I could not, however, make it reuse a method from another class, much less, from another jar, confirming what the study found. Has anyone had any success?

Regardless, as cool as AI is (I love chatting with ChatGPT!), developers cannot just take whatever it gives us. I know that's obvious to many, but it apparently needs to be emphasized to some.

Case in point, I was using ChatGPT the other day to come up with a couple of Python scripts for manipulating Excel spreadsheets. The scripts came out almost perfect. I had to ask it to refine them a few times. After all that, there was still a bug that I fixed by swapping two statements. I also ran into an error message. ChatGPT apologized and gave me an alternate (working) version. I forgave and thanked it, of course :).

Admittedly, I have yet to ask Copilot for new code. I've only used it as a more intelligent auto-complete feature. When it offers to help, I quickly review what it's proposing, and accept or decline it as appropriate. It has mixed up my variables in some cases.

💡
More than ever, developers need to have excellent code-reviewing skills.

No more just-skimming-through that some people tend to do. This rule applies to both the developer that's introducing the AI-generated code and the teammates reviewing that code.

Back to duplicate code...

💡
As much as possible, all developers should be aware of existing functionality not just within the application they're working in, but also elsewhere in your codebase.

Think twice before asking Copilot to generate new code for you. It warrants some due diligence.

For however many years we've all been in this industry, we have been making sure that we reuse as much code as practically possible, instead of copying and pasting. Don't let blind reliance on AI undo all that work on engineering excellence in the blink of an eye.

0
Subscribe to my newsletter

Read articles from Ever A. Olano directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ever A. Olano
Ever A. Olano

Inspired by a computer that printed "Hello, Ever" on the monitor at a science field trip. Fascinated by Basic in high school, then Turbo Pascal in college for starters. The rest is history. And yes, that's the answer to "How do you say you're seasoned without saying you're seasoned?"