Skip to main content

Coding with AI: Strategies for Aggressive and Cautious LLM Backed Programmers

The process of using ChatGPT to write code is sometimes challenging. Here are my favorite tips and tricks for utilizing LLM's to write code faster!
Created on August 18|Last edited on August 18
The rapid rise of Large Language Models (LLMs) like ChatGPT has divided the programming community into two distinct camps. Some programmers wholeheartedly embrace LLMs, leveraging them to the fullest, while others remain more careful, selectively utilizing these tools. Here's a guide that caters to both styles, offering insights and tips tailored to different levels of engagement with AI.
For the Aggressive LLM Programmers: Maximize Your AI Potential
Programmers in this category are eager to make the most out of AI tools and often explore unconventional ways to integrate them into their workflow.

Max Out Context, Always

With ChatGPT powered by GPT-4, I can get about 300 code lines of context usually. Providing a detailed overview of as much code as you can offers huge benefits when it comes to GPT coding. Also, when pasting errors into ChatGPT, it’s always better to give the model as much as it can handle, meaning copying large amounts of terminal output. The great thing about LLM's is that they don't seem to be phased by large amounts of seemingly irrelevant console errors. Sometimes, I even like to structure my code in a way that can be easily fed to the model with all relevant code fitting in the 300 line window. Sometimes more abstraction is a great way to achieve this.


Ask the LLM to Write Shell scripts

The obvious way to use ChatGPT for coding is to write code in typical languages like Python or C++. Bash should not be forgotten! They are powerful ways to automate tasks, and often are underutilized by programmers, and also (at least for me) less understood in terms of syntax, so ChatGPT is a great option.

Example: The complete file creation sh script code embedded
Sometimes, when working on a task that involves creating multiple small files, instead of creating the files manually, I will ask ChatGPT to write a shell script that will automatically create the files, and add the specified content to the files. This dramatically increases the speed of accomplishing the task. This may seem a little bit overkill, but personally I think that anything that can automate existing manual tasks is invaluable, and can accelerate the pace of innovation for any programmer.


GPT Powered aliases

This is another example of taking advantage of using ChatGPT to do tasks that previously would’ve been less justified in terms of time spent. I personally love bash aliases that can give me more visibility over my files in the command line. Tasks like counting the number of files is a directory, listing the files by creation date, or listing the sizes of all directories are all useful bash aliases to have when working with big data, and ChatGPT can almost always write these aliases in a single shot! My .bashrc is growing quite quickly due to Chatgpt, and my command line is becoming much more personalized and useful.


Translate code from different languages

It’s important to remember that since the advent of ChatGPT, code is now somewhat language agnostic. What I mean is that code written in one language now has strong utility in another language, as long as ChatGPT can translate the code. Now its important to note that ChatGPT likely will make mistakes when translating code from one language to another, however, its likely it will do much better compared with being prompted to write the code in natural language. I personally have translated code from objective-C to Swift for an iOS app, and it did a pretty good job!


Rather Safe than Sorry

This tip is one of my personal favorites. For any project, the approach to tackling the task at hand can make or break the project. I like to come up with an initial approach for projects I'm working on, and then ask ChatGPT to come up with alternative options, and even critique my approach. Recently I was working on a task that required condensing down a 32 frame video into the most relevant 8 frames of the video. My initial thoughts were that the videos would need to be manually scrubbed by a human to at least find enough data that could be used to train a simple model that could locate relevant sets of frames for the remaining videos. However, asking ChatGPT for ideas, it suggesting using a Temporal Difference algorithm to find outliers in the 32 frame video. I had it write the code, and it worked amazingly! Would would’ve costed me 2-3 days previously, now was a simple 2 hour task! Times are good as a programmer.

For the Cautious LLM Programmers: Thoughtful and Selective Engagement

Programmers in this category may prefer traditional methods but recognize the value of AI in specific scenarios.


Test More

When writing your code, actively communicating with ChatGPT can help to catch bugs quickly, and can also help to write tests for your code. One of my favorite tests to write is when making datasets for my ML models. What I will do is have ChatGPT write the dataset object, and then have ChatGPT write a test that will read from the dataset, un-preprocess the data, and save the data to a file. The ability for the model to un-preprocess the data is usually a good sign that the original preprocessing was done correctly, and also a great way for the LLM to find bugs in the original code.


Explain code

AI can be an invaluable asset for unraveling complex, poorly-documented code. Suppose you inherit a legacy project filled with convoluted code. In that case, you can use AI to parse the logic, providing clear and comprehensive explanations that aid future development. This is one of my favorite tactics for understanding new code. I will simply paste code in and ask the model to summarize how the code works. It’s almost like having a conversation with the original code author!


Debugger Context

Stumped by a cryptic error message? AI can be your interpreter. Feeding the error message into ChatGPT can translate that confounding text into an actionable solution, guiding you directly to the problem's root. A huge way to accelerate this even more is to utilize a visual debugger that allows you to copy the exact value of certain variables. This allows the model to have a deeper understanding of why code is failing, and it can point you in the right direction with a much higher accuracy!


Know your context

Knowing when to engage with ChatGPT—whether to continue an existing conversation or start a new one—is crucial. Making this decision can depend on the complexity of the issue at hand or the continuity of the topics being discussed. I find sometimes the model will misunderstand my task early on, and the errors compound as the context grows. In this situation, I personally like to either start a new conversation, or simply go back to my original prompt, and redo it, as opposed to trying to correct prompts later in the chat.


Stack Overflow vs. GPT? It's tricky

Choosing between AI and community-driven insights from platforms like Stack Overflow can be nuanced. While AI offers immediate responses, community input might provide broader perspectives. A balanced approach, drawing on both resources, can often yield the best results. I generally like to start off with ChatGPT, but if it seems as if the model is uncertain, I will do a “sanity check” on Stack Overflow to see if there are any issues. One trick I sometimes do is enter my prompt into ChatGPT, request a response, and during the time the model is processing my input, I will do a google search for my prompt. This seems to be the most efficient way to debug most errors in my experience.


Ask for pseudo-code for new code and existing code to understand

If you're exploring new algorithms or trying to get a handle on existing ones, AI-generated pseudo-code can be a lifesaver. By translating high-level concepts into simple, human-readable form, AI can help you understand, modify, or implement complex algorithms with ease. This is great for programmers who dont particularly trust ChatGPT to write their code. By asking the model to write sudo code, it allows you to verify the logic of different code, as well as help you form an understanding of the code you need to write.
These strategies depict the measured and thoughtful ways cautious programmers can incorporate AI into their workflow. Whether it's testing, understanding code, or simply making daily tasks more efficient, AI tools like ChatGPT offer substantial support without overwhelming traditional practices. By leveraging these tools wisely, even the more cautious programmers can enjoy the benefits of AI-enhanced development.

A Fast Paced Future

Whether you're an aggressive LLM user who pushes the boundaries of AI or a tentative user who prefers a more cautious approach, the integration of AI into software development is only going to grow. By understanding and embracing these tools according to your style, you can redefine the way you code and stay at the forefront of innovation. The balance that works for you is the key to unlocking new levels of creativity and efficiency.


Tags: ML News
Iterate on AI agents and models faster. Try Weights & Biases today.