BRYAN HUNT

Using ChatGPT for API Discovery

There has been a lot discussion around the idea that the task of programming will be offloaded to AI like Chat GPT in the next n number of years, and while I have no idea whether or not that will be the case, I can say it's been a great tool for code exploration and checking things off my "someday/maybe" list.

One of my favorite parts about ChatGPT at the moment, is that it provides a fast and easy way to discover API's in a specific context without having to read the entire manual first. 

At a surface level, that sounds like a terrible idea. We should understand the system we're working in (at least to a reasonable degree) before we start slapping code into an editor to see if it sticks. But I think there's a place for this.

Unfortunately for me (and I'm sure for many of us), time is limited, so discovering an API can be a time commitment that will likely never happen. Even when we're already familiar with the language or framework, reading into new areas of the code base we've never had to utilize or may be lesser known due to having very specific uses, may not be discovered until after a more verbose work-around has been implemented.

For example: 
One day my colleagues on the design team asked if there was any way they could "autocomplete" HTML attributes like class and id in VS Code when editing an .erb file. I realized I had also been typing each character in <div class=""... every time I wanted to add a new div with some styling.

Now I'm actively aware of this, I can't simply ignore it. So, I thought "surely this must be a simple case of configuration, right?" and went about my normal routine of googling variations of "autocomplete" and "attributes". 

And as I expected, I came across the guide for configuring language support and for snippets. Even though these solved the problem in a specific way, it wasn't exactly what I wanted as there was no contextual awareness that I was typing an HTML attribute. So, that meant more research and more reading of the manual, which meant I was about to throw in the "I've already spent too much time on this" towel. 

But I decided to see what ChatGPT had to say. As expected I received a very good, very tailored response
Even after the first iteration, I felt like I had a starting point. By the last iteration I had a more specific direction. It's unlikely I would have known about the vscode.languages.registerCompletionItemProvider method inside of some concept code within a few minutes, let alone hours. With these results, I had the confidence that I could complete this  side-project within an acceptable amount of time and gained some valuable knowledge along the way. 

And sure enough, my "someday/maybe" to-do become "done (ish)". Sure, I still had to configure the plugin to get it to work using other open source plugin examples, but it works, and I can add more and more attributes or customizations for myself and the rest of the team. It may not be great, or tested, or perfect, or even necessary, but it's live and actively solving my annoying issue. It's "done-ish". 

Every time I type <some-element cl and see that auto complete pop up, it puts a smile on my face because it's something that exists that otherwise wouldn't if I did not have a guide throughout the development process.

I'm looking forward finally to knocking out a few of those small, personal productivity tools that I've been wanting to build but never seem to have time to complete. But I'm even more excited as the prospect of learning the ins and outs of the tools I use with a helpful, contextually-aware guide.