25 AI tips to boost your programming productivity with ChatGPT

digitalspeed-gettyimages-1322205545

dhapecharge/Getty Images

Over the past year or so, I’ve been experimenting with using ChatGPT to help turbocharge my programming output. When ChatGPT helped me find a troubling bug, I realized there was something worthwhile in AI.

Also: Your dream programming job demands this language, every site agrees

Many people I talk to think that AI is a magic genie that can manifest an entire program or app out of a single, barely-formed wish. Here’s a much better analogy: AI is a power tool. Sure, you can use an old-fashioned saw to cut wood, but a table saw goes much faster. Neither tool makes furniture. They simply help you make furniture. Keep in mind that the AI isn’t going to write your code for you. It’s going to help you write your code.

Although there’s no objective way for me to tell you exactly how much ChatGPT has helped me, I am fairly convinced it has doubled my programming output. In other words, I’ve gotten twice as much done by using ChatGPT as part of my toolkit.

I’ve mostly been using ChatGPT Plus rather than the free version of ChatGPT. Initially, it was because the GPT-4 model in Plus was better at coding than the GPT-3.5 model in the free version. But now that both support some variant of the GPT-4o model, their coding capabilities are identical. However, you only get so many queries with the free version before you’re asked to wait a while, and I find that interrupts my programming flow. So, I use the $20/month Plus version.

Also: The best AI for coding (and what not to use)

Thinking back on all my projects, I realized there are some tangible tips I can share about how to get the most out of an AI programming partner. Here you go.

1. Give the AI lots of small jobs

The AI doesn’t handle complex sets of instructions well, especially if you expect it to essentially do product design. But it is extremely good at parsing and processing small, very well-defined sets of instructions.

2. It’s helpful if you think of the bot as someone at the other end of a Slack conversation

Rather than the pacing that might come from an email back-and-forth with a colleague, which might have each interaction separated by hours, imagine you’re in a Slack chat where each interaction is much smaller, but separated by seconds.

3. For more complex routines, prompt iteratively

Start with a simple assignment and when that’s been properly written, add more to it, element by element. I simply cut and paste the previous prompt, adding and removing bits of the prompt, as I get chunks of code that work for what I’m looking for.

4. Test every little chunk of code the AI returns

Don’t ever assume the code will just work. Patch it into your project and see how it performs.

5. Use the debugger

For a more in-depth test, don’t hesitate to drop into the debugger and walk through the code generated by the AI step-by-step. Watch the variables and exactly what it does. Remember, it’s OK to let it write code snippets for you as long as you check every single statement and line for proper functioning.

6. You don’t need Al coding assistance built right into your IDE

Many coding tool vendors are pitching the idea of integrated AIs right in their tools. Among other things, this enables them to upsell you on the AI features. However, I prefer using ChatGPT for coding as a tool completely separate from my development environment. I don’t want an AI to be able to reach into my primary coding environment and change what’s there.

7. Feel free to cannibalize lines of code from generated routines

 You don’t always have to use everything the AI produces for you. In the same way that you might go to Stack Overflow to look for code samples, and then pick and choose the lines you want to copy, you can do the same with AI-generated code.

8. Avoid asking the AI to do proprietary coding or use institutional knowledge it doesn’t have

 AI large language models run off of training data or what they can find on the web. That means they generally don’t know anything about your unique application or business logic. So avoid trying to get the AI to write anything that requires that level of knowledge. That’s your job.

9. Give the AI examples to work on so it understands the context of your code

I gave ChatGPT a snippet of an HTML page and asked it to add a feature to expand a block of text. It gave me back HTML, JS, and CSS. I later asked it for an additional CSS selector and then asked it to justify its work, whereupon it explained to me why it did what it did. All of that worked because the examples I gave it to start helped it understand the context.

10. Use the AI for common knowledge coding

I find the biggest benefit from AI code is when I use it to write blocks of code that use common knowledge, popular libraries, and regular practices. The AI won’t be able to write your unique business logic. But if you ask it to write code for capabilities that come from libraries and APIs, it will save you a ton of time.

11. Feel free to ask for one- or two-line snippets

Even if you need something that might only generate a line or two of a response, use the AI as you would use any research tool if it can save you time.

12. Tell the AI when the code it wrote doesn’t work

This, of course, can only work if you test the code generated. I find that the AI often spits out incomplete or non-functional code. Tell it what isn’t working, and perhaps make a suggestion to clarify. Then ask it to write something new. It usually does, and that revised code is sometimes better than the original.

13. Use one Al to check the work of another Al

It’s often interesting to see how two different language models interpret the same block of code. As we’ve seen, not all language models work all that well, but their results can be instructive. You can even have one ChatGPT session check the results from another ChatGPT session.

14. Use the AI to write CSS selectors

CSS selectors are the expressions coders use to define an element on a web page for styling or other actions. They get complex and arcane quickly. I often copy a block of HTML and ask for a selector for a given piece of that HTML. It can save a lot of time, but keep in mind that you’ll usually have to iterate, telling the AI that the first few selectors don’t work until it generates one that does.

15. Use the AI to write regular expressions for you

Regular expressions are symbolic math sequences most often used for parsing text. I dislike writing them almost as much as I dislike writing CSS selectors. The AI is great at writing regular expressions, although you’ll definitely need to test them.

16. Use the AI to test regular expressions

I use an app called Patterns for testing generated regular expressions on my Mac Studio. But the AI can help as well. I often feed a separate instance of the AI a regular expression generated by ChatGPT. Then I ask that separate instance, “What does this do?” If I get back a description in line with what I wanted the function to do, I feel more confident the AI did what I wanted.

17. Let the AI do complex loop math

As with CSS selectors and regular expressions, complex loop math can be tedious and error-prone. This is an ideal application for an AI. When specifying the prompt, don’t tell the AI what’s in the loop. Just let it write the appropriate loop wrapper elements, then write the business logic after that’s working.

18. Use “What is wrong with this code?” as a prompt

I will often feed blocks of code, especially regular expressions generated by the AI, to the AI. It can be very instructive to see what the AI thinks is wrong with the code, often highlighting error conditions that the code doesn’t test for. Then, of course, ask the AI to regenerate the code fixing the errors it found.

19. Use “What does this do?” as a prompt

Likewise, I like to feed blocks of code to the AI and ask it “What does this do?” It’s often instructive, even for my own code. But the biggest benefit is when I’m working on code written by someone else. Feeding a function or a block to the AI can save a ton of time reverse engineering that original code.

20. Know when to give up on the AI

Sometimes, the AI just can’t do the job. I’ve found that if you try to have it rewrite its code more than two or three times, you’re past the point of no return. If you really want AI-generated code, start with a brand-new, reworded prompt and see what you get from there. And sometimes, you’ll just have to go it on your own.

21. Be specific in your function and variable naming

The AI picks up intent from variable and function names and writes better code. For example, specifying a variable name as $order_date helps tell the AI that you’re dealing with both an order and a date value. It’s a lot better than something like $od. Even better, code generated from well-named variable names is also often more readable, because it knows to use more descriptive names for the other variables it creates as well.

22. Read the pre- and post-code notes

The AI usually generates some notes about each prompt before and after the code it writes. There can be gems in there that can help you understand what the AI did or how it approached the problem. Sometimes, the AI will also point you to other libraries or functions that could be useful as well.

23. It’s OK to later go back and ask for more help on a code snippet

Grab the various pieces of code from your project to illustrate what you need, tell ChatGPT to read them, and then ask for what you want. I needed to build in an exclusion for input fields in an expanded area, and I went back in and asked. Less than a minute later I had code that would have taken me somewhere between 10 minutes and an hour to write myself.

24. Use the Al to help you rewrite obsolete code blocks

I had a PHP module written in an older version of PHP that used a language feature now deprecated. To update the code, I pasted the deprecated code segment into ChatGPT and asked it to tell me how to rewrite it to be compatible with most current PHP release. It did, and it worked.

25. Use AI to help you write for less familiar languages

I’m very comfortable picking up new programming languages, but I’ve found that the AI can be really helpful if I need to code in a language I’m not an expert in. I just ask it how to write what I want, and specify the language. Let’s say I want to know how to do a case statement in Python and I’ve been doing them forever in Perl. Just ask “compare writing a case statement in Perl and Python” or “how to concatenate a string in Python vs PHP.” You’ll get a great comparison, and it makes writing that unfamiliar code much easier.

Here’s a bonus tip. Check with your company about the legal issues of code generated. If you’re not sure where to start, read my article on AI and code ownership. If you use the tips I shared with you, you’ll never be using the AI to write unique business logic or the core of what makes your code unique. As such, you’ll likely be able to retain the copyright of that code, which should make up the key element of your unique value.

I write code for internal company use or open-source code, so I’m not terribly concerned with ownership issues when it comes to AI-generated snippets.

Have you used an AI to help write code? Do you have any tips to add to my list above? Let us know in the comments below.


You can follow my day-to-day project updates on social media. Be sure to subscribe to my weekly update newsletter, and follow me on Twitter/X at @DavidGewirtz, on Facebook at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, and on YouTube at YouTube.com/DavidGewirtzTV.

Source Link

LEAVE A REPLY

Please enter your comment!
Please enter your name here