Skip to main content

Tips for Leveraging Your GenAI Code Assistant

Brenno Oliveira of Kyndryl explains how to craft prompts that will maximize the effectiveness of AI coding sidekicks

TechChannel AI

While everyone is talking about how accurate or inaccurate Generative AI (GenAI) is, how it will make some jobs obsolete or how you should always use it or never use it, I would like to look at this topic a bit differently. How can you get the most out of your trusty sidekick? Are you sure you’re not hindering your learning by using it? Is there a way that we can be more efficient and capable but still learn a lot in the process?

In this article we will go over a few recommendations based on my own experience that have led me to get great results from code assistants and still learn a whole lot in the process. Now let’s get into it.

Turn Off Auto-Complete (Most of the Time)

Now, this might sound strange, but I don’t use my code assistant’s auto-complete that often. When you start using it you feel blazingly fast, but after some time you might notice that you can spend more time waiting for it to generate something closer to what you want compared to just writing it yourself. I prefer to write most of the code myself and chat with the assistant when I need to validate ideas, explore alternatives, conduct research or do similar tasks.

Another problem with auto-complete is that you don’t give yourself a good chance to properly validate that suggestion; you’re trying to get something done so you might just go with the flow and accept the output. This can lead to small bugs on the code that can be harder to debug since you didn’t write the code yourself.

It could also implement something in a way that doesn’t consider the requirements for your application, since the AI might not have any context around those requirements—for example, imagine your application needs to be extremely memory-efficient, but the AI’s suggestions are using functions that create multiple copies of objects or data structures.

However, auto-complete is still an extremely powerful tool to increase your efficiency. GenAI is great at identifying and repeating patterns, so you should still turn it on to speed up writing boiler plate, repetitive code, or when you need to manually work with well-structured data like JSON or XML to speed up that process.

Provide Context and Your Objectives

I mentioned that a lack of context can lead to suboptimal responses in the previous topic, and I consider this to be one of the most important points if you’re interested in getting more applicable, higher-quality responses from your code assistants.

Let’s imagine you need to architect and write a solution to replicate data being generated by CICS transactions in real time up to the IBM Cloud, and that performance and data consistency is extremely important. You would also like to use Java for any code that needs to be written.

If you provide very little context and ask it something like “How to write a data replication solution,” you will likely get an answer that is helpful but does not directly address your specific use case:

However, if you provide all the context around what you need, what is important for you, and what tools/languages/platforms you would like to use, you will get a much better response. Let’s try again with a prompt that provides more context.

I need to develop a data replication solution. Performance and consistency is the most important aspect for this solution. The data will be generated by CICS transactions and need to be replicated in real time up to the IBM Cloud. I need to write this solution in Java.

As you can see, the response is light-years better than the first one. We’re directed to applicable technologies that might interest us for our specific use case, like IBM Data Replication for real-time replication, Kafka via IBM Event Streams for high-performance and data consistency, a Java-based Kafka Consumer and an IBM Cloud database.

Providing context is essential for obtaining relevant answers to our questions, so make sure to give as much information as necessary.

Instruct the AI to Behave in a Certain Way

Another powerful strategy you can use is that you can provide a set of instructions to the AI on your very first prompt, and it will follow those instructions during the rest of your conversation.

With this you can have a Python expert beside you who will teach you anything you want and provide you with real-world examples, rate your knowledge by asking you a set of questions or problems and suggest what you should learn next.

You could also have your assistant help you review your code to identify possible areas of improvement or to generate developer documentation in the specific format you want for your application; the possibilities are endless.

A cool trick you can use that also relates to the previous topic is that you can have the AI help you prompt itself. You don’t know what you don’t know, so why not have your assistant help you fill the gaps. Let’s look at an example.

I’m interested in building an application that can analyze logs to find anomalies based on past incident data. You should ask me five simple-to-answer questions about my use case in order to fine-tune your response, and provide a short explanation of why those questions matter for the final solution.

This, combined with any context you can provide that you know is applicable to your use-case, will help generate much better results right away.

Final Tips

This article is nearing its end, but I still would like to point out a few quick tips that will help you get more out of your AI assistants:

Request evidence and references on your prompt

This allows you to validate that the information provided is accurate and will also help you with links for future research if needed.

Ask follow-up questions

If something the AI said is not quite clear, or if you would like to delve deeper into a specific topic, you should ask it follow-up questions about that topic—it will generally still have the context of your previous questions and instructions so it should continue to behave as you’ve instructed it to up to a certain point.

Confront it if something doesn’t add up

Not every response will be 100% accurate—if you tell it it’s wrong it will try its best to correct itself. However, if that doesn’t work immediately, don’t waste too much time—if you know something is incorrect it’s not worth it to try to get a perfect answer.

Request code snippets

These are great for a quick start when using a new library or feature and, depending on your experience level, might be just enough to get you where you need to be.

Conclusion

While some of these tips might seem simple or obvious, especially the final ones, when you add them all up you can get amazing results from your prompting sessions. I hope you make as much use out of these as I have, and if you try them, I’d love to hear how it has improved your interactions with our trusted daily companions.

If you’re looking to learn a bit more about AI, I recommend you read this great article by my colleague Pat Stanard about AI for discovery here at Tech Channel. Happy Prompting!


Key Enterprises LLC is committed to ensuring digital accessibility for techchannel.com for people with disabilities. We are continually improving the user experience for everyone, and applying the relevant accessibility standards.