This content originally appeared on Level Up Coding - Medium and was authored by Mykhailo Kushnir
Github continues to walk down the path of simplification of coding. Copilot extension was a drastic change in the efficiency (at least for me) and now the other vital aspect of the software engineering process would be handled. I’m talking about the documentation.
That’s where Copilot Labs comes in. Copilot Labs is a tool that can help you or someone else understand how your code works. It provides you with Machine Learning generated explanation just like this:
Recently I’ve been added to the group of testers for the Copilot project so I’ve decided to give it a go and ask it to explain a few of my coding snippets from previous tutorials.
Web Scraping
How I scrape lots of sites with one python script
In the article above I’ve shared a link to the repository with a configurable script that helps me parse lots of sites and is a good template to start. Human explanation of the main part of code would be that it:
- Loads all the configuration variables
- Creates a Selenium driver
- Goes to the target page and scrapes data according to selectors
- Saves data
- Quits the driver
The explanation given by the machine wasn’t that cheerful:
I would’ve been a bad tester if I wouldn’t give it a second try. Copilot Labs allows you to change the start of the explanation so you can direct it a little. Here are the next few attempts at getting more human-readable descriptions:
Plots
Five useful Pandas scripts for financial time series plots
In the article above I’ve created five Python methods to visualize various financial data. While it’s already quite well documented with the help of the main Copilot extension, I wanted to see what Labs can tell me about it.
I’ve started with the simplest one the method that plots standard deviation:
And here’s the explanation generated by the machine:
While it seems unnatural, it’s very precise and explains each step of the method. I guess, if humans would’ve been able to communicate that way — there would’ve been fewer bugs and miscommunications in software development.
Still, that was probably the best explanation for the code snippets shared in the article. More complex methods make Copilot Labs repetitive and it clearly doesn’t understand the value of the method — it speaks more about the technical details. Here’s an example of a function that plots two line plots at the same figure:
Docker
What about scripts? It seems that can be a good place for Copilot Labs. For example, here’s how it handles a simple Docker file:
https://github.com/destilabs/ethscan/blob/main/Dockerfile
In this particular case, it’s obvious that Labs extension goes beyond just translating the code and learning the actual meanings of commands. Perhaps, it has something to do with how well those commands are actually documented.
Conclusion
Copilot Labs is a great tool for documenting structured scripts like Docker build files and providing brief explanations of code snippets. However, it falls short when it comes to providing large amounts of documentation. There’s still a use case for it as it provides a good enough explanation if getting a relevant starting utterance and it can translate your code to other languages.
If you’ve enjoyed this article, be sure to subscribe to this blog for more articles like this.
The tool that tries to explain how your code works was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Mykhailo Kushnir
Mykhailo Kushnir | Sciencx (2022-06-19T11:54:42+00:00) The tool that tries to explain how your code works. Retrieved from https://www.scien.cx/2022/06/19/the-tool-that-tries-to-explain-how-your-code-works/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.