DEV Community

Henrik Warne
Henrik Warne

Posted on • Originally published at henrikwarne.com on

Programming With ChatGPT

Using ChatGPT when I code has been a real productivity boost for me. Instead of reading an example on Stack Overflow and figuring out how to adapt it to my particular case, I immediately get code tailored to my specific needs. I my mind, generating code is a perfect use case for LLMs, since I will always test the generated code. If it isn’t working, I’ll find out right away, so hallucinations is not a problem.

Programming

A while ago, I needed to write code to download data from a Google bucket. I had never done that before, so I started with this query:

Give me a Python program that connects to a Google Bucket and downloads all files that have an ISO date string in the name.
Enter fullscreen mode Exit fullscreen mode

There was some trouble with authentication, so I wrote a few queries about how that works. Then, when the basic download worked, I used:

For files that are zip-files, give code that unzips them (in memory), then iterates through all the lines in those files.
Enter fullscreen mode Exit fullscreen mode

Being able to get code tailored to what I want is really helpful, and speeds up my work a lot. I like to work in small steps – getting a basic case working first, then adding functionality bit by bit. This workflow works well with ChatGPT. It is quite rare that I get an answer with an error in it. More common is that the code doesn’t do exactly what I want, or that it is using one framework, and I would prefer another. But then I just modify my query accordingly.

In all cases though, I will test the code I get back. Both to make sure I does what I want, and to make sure I understand how it works. The reason I want to understand how it works is that I want to be able to trouble shoot my application if it doesn’t work as expected. If I don’t understand how the code works, I can’t trouble shoot it.

I see ChatGPT as another useful tool programmers can use – it makes us more efficient. However, it is still a tool controlled by the developer. I have seen blog posts projecting that all coding in the future will be done by LLMs, with no need for programmers. I am skeptical of this claim, both because it is hard to specify the behavior of a system only in English, and because I think it would be difficult to figure out why a system is not doing what it is supposed to do.

I have paid for ChatGPT for about a year now. For a few months when ChatGPT-4o came out, I stopped paying, since there didn’t seem to be any benefit of paying for it. However, once I started getting notices of rate limiting, I started paying again. I think it is a bargain at $25 a month, given how much more productive I am.

Often when I look at the answer to a query, I want to use page up and page down (because there is more than one page of it). One small annoyance is that that often doesn’t work. The fix is to press the tab key to make them work again.

Other Tools

Many companies are careful not to expose their source code to any outside vendors. My workflow of asking for specific pieces of code works well in this regard. It does not depend on using any existing code for context.

I have tried GitHub CoPilot a bit on some personal projects, but I prefer using ChatGPT. I also tried Claude briefly, but I found that I have become used to the way ChatGPT formats its answers.

Other Uses

I also often use ChatGPT instead of Google, or man-pages, for shell commands. For example:

Give me the jq command that counts the number of objects in a json array.

Give me the curl command to send a POST with an empty body.

Give me a sed command that removes the beginning time stamps from lines looking like this:
2023-08-25 10:15:32,104 - INFO - User logged in from IP address 192.168.1.1
Enter fullscreen mode Exit fullscreen mode

I have tried using ChatGPT to generate texts, but I have always been disappointed at the result. It always sounds fake to me. Using it to summarize texts has also been disappointing. When I knew the source texts well, the summaries always sounded too generic, without any real insights. However, I am using ChatGPT more and more as a substitute for Google. For example, summarizing concepts, or asking questions about language use.

Conclusion

Using ChatGPT for programming is almost the perfect use case. Since I always test the result, any hallucinations will quickly be discovered. And hallucinations are rare. Most of the time I get code that does what I want really fast.

Top comments (5)

Collapse
 
hosseinyazdi profile image
Hossein Yazdi

I use phind.com instead of ChatGPT. It's directly meant to be an AI programming assistance. It's free as well.

Collapse
 
lindamiles profile image
Linda

I have also been using chatGPT for similar/same tasks. Your article resonated with me, so I am going to include it tomorrow's issue of my daily tech newsletter, dailysandbox.com

Collapse
 
henrikwarne profile image
Henrik Warne

Thanks, I'm glad you liked it! I've been meaning to write this down for a while now - it really is a useful tool for me.

Collapse
 
mengqinyuan profile image
mengqinyuan

In China, I use TONGYI LingMa. You can search the plugins in your IDE and install it. You need to sign up a account witch only need to enter a message.

Collapse
 
king_triton profile image
King Triton

ChatGPT helps the strong and destroys the weak