paint-brush
How GitHub Copilot Can F**k Up Your Codebaseby@kaumnen
1,140 reads
1,140 reads

How GitHub Copilot Can F**k Up Your Codebase

by kaumnenFebruary 17th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I used GitHub Copilot recommendation for a piece of code (which was false), and it caused me a lot of google-ing. As GHC learns from the publicly available codebase, you have to watch out for bugs/problems written by other devs.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How GitHub Copilot Can F**k Up Your Codebase
kaumnen HackerNoon profile picture

Let's Talk About AI Tools for Code Completion.


After spending quite a bit of time debugging my code, what's wrong with it, I've found the 'bug'. Not the ordinary one.


Don't fully rely on AI. Seems simple right? However, when you are doing some easy/repetitive stuff, you might fall under influence of just 'tabbing'.


What was the 'bug' anyway?


I was making a Twitter bot in NodeJS. Get some data from Reddit, and post it on Twitter bot account.


First off, I need a library, to simplify things about auth and whatever. A'ight, done.


npm install, make file structure, git init.


Here comes the fun part. I'm writing a constructor for a Twitter client. It needs 4 elements:

  • API key

  • API secret

  • Access token

  • Access secret


Okay, fair enough.


Constructing the Constructor


First one, it's okay. TAB.


appKey field for Twitter API constructor


Seems good, TAB!


accessToken field for Twitter API constructor


Awesome. GitHub Copilot is great!


accessTokenSecret field for Twitter API constructor


It's so easy. TAB and there we go. Constructor finished!


Testing


Let's try to get a simple 'Hello World!' tweet out there.


401, Unauthorized.


Umm, what? Let's go to the .env file, let's check if the naming is correct. Copy, paste.


Check.


401, Unauthorized.


Okay, let's check for Twitter stuff. Check permissions, regenerate keys.


Check.


401, Unauthorized.


Now comes the part where I tried to debug code, try a different library that supports Twitter's V2 API. No success.


Debugging


Google, google, google. Try this, try that. Progress: NULL


I go for a walk, hoping for an 'Aha!' moment.


No luck. Back to work! Open Postman. Input parameters. Check headers, check body.


Send.


It worked!


Hmm, what could it be? Open postman, copy the curl request. Paste it in Notepad++.


I previously turned on debug mode in my code, copied the curl request from there too. Paste it in Notepad++.


Double-click one. Check.

Double-click another one. Check.

Another one. Check.

...

One is missing. How's that possible??


Now I went to the library docs.


Do you know what I did? Doesn't make sense, but let's try. Better than nothing.


Search for a method to input custom headers.


Nope. I did google (a lot) previously, about errors, and whatnot, but either there was no answer, or it was a typo in the .env file.


'Aha!' Moment


Maybe... It's the wrong naming of the constructor fields. So I check. Now I rely on IntelliSense and typing fields.


appKey field for Twitter API constructor


Seems good.


appSecret field for Twitter API constructor


Keep on.


accessToken field for Twitter API constructor


Okay. Onto the last one.


accessSecret field for Twitter API constructor


Wait, what? Wasn't it accessToken..? My literal reaction was: NO WAY! Are you kidding me?! 😂


GitHub Copilot:


wrong field naming, Twitter API constructor


IntelliSense:


right field naming, Twitter API constructor


GitHub Copilot’s AI was trained on the publicly available codebase. So, you have to take care of bugs others have written in their code!


GHC recommended I use the accessTokenSecret field for a constructor, but the problem was that there isn’t a field with such a name!


The right one was accessSecret, recommended by IntelliSense engine.


There is Always an Opportunity to Learn


So yeah… There are zero places that can teach you those things. You must experience them and unlock that kind of knowledge. 😄



Keep Going!


These are my .02 cents. Don't let code completion AI tools rule your work. I'm sure there is a lot of funny stories like this. But we all make mistakes. Embrace them as learning opportunities.


I don't blame GHC for this. I blame myself. But whatever. At least I got some experience. There is always space for improvement.


Fun one for sure.


Thank you for reading!

_ktb


First Published here