# Improving the prompt to the AI to get better code

DevFeed: [Improving the prompt to the AI to get better code](<https://devfeed.tech/articles/improving-the-prompt-to-the-ai-to-get-better-code-30758.md>)

Original publisher: [Read original article](<http://blog.vanillajava.blog/2025/07/improving-prompt-to-ai-to-get-better.html>)

Author: Peter Lawrey (noreply@blogger.com)

Published: 2025-07-17T15:56:00Z

Content type: opinion

Language: en

Sources: [Vanilla Java](<https://devfeed.tech/sources/vanilla-java.md>)

Topics: [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [Code](<https://devfeed.tech/topics/code.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [Latency](<https://devfeed.tech/topics/latency.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [change](<https://devfeed.tech/tags/change.md>), [code](<https://devfeed.tech/tags/code.md>), [exercise](<https://devfeed.tech/tags/exercise.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [latency](<https://devfeed.tech/tags/latency.md>), [library](<https://devfeed.tech/tags/library.md>), [opinion](<https://devfeed.tech/tags/opinion.md>), [performance](<https://devfeed.tech/tags/performance.md>), [prompt](<https://devfeed.tech/tags/prompt.md>)

## AI overview

The article compares how several AI systems improve a Java code-optimization task when given a more detailed prompt. It concludes that prompt refinement improved weaker results, but the systems generally missed the same byte-array optimization and did not consistently reduce duplication, while longer processing did not produce a significantly better answer in this case.

## Source excerpt

In a previous article I looked at one-shoting a solution to optimise code to show the variation in different AI. Thsi is the not the best way to get what you want however. More often you need to either refine the prompt or give feedback. After one-shoting the same prompt on multiple AI, I have created a refined prompt based on the various concerns with previous results. The prompt Based on the results in a previous run Asking multiple AI to optimise the same code Suggest how to implement this more optimally using low latency techniques to minimize any objects created. ## Use - a ThreadLocal for temporary data. - simple maths rather than a library, add comments for clarity if needed. - offset in the form ±hh, ±hhmm, or ±hhmmss, using the shortest form that does not lose information, where hh, mm, and ss are the hours, minutes, and seconds east (+) or west (-) of UT - return a `intern()` String. ## Don't use - String.format - String operations that create objects. - any colons, they aren't required - reduce code duplication ## The code private static String formatOffset(int millis) { String sign = millis < 0 ? "-" : "+"; int saveSecs = Math.abs(millis) / 1000; int hours = saveSecs / 3600; int mins = ((saveSecs / 60) % 60); int secs = (saveSecs % 60); if (secs == 0) { if (mins == 0) { return sign + twoDigitString(hours); } return sign + twoDigitString(hours) + twoDigitString(mins); } return sign + twoDigitString(hours) + twoDigitString(mins) + twoDigitString(secs); } private static String twoDigitString(int value) { return Integer.toString(value + 100).substring(1); } I typically use asciidoc rather than markdown, but trying to keep this example simple. None of the AI considered using a byte[] event though String now uses a byte[] as an underlying store. I asked each one to change the implementation to use a byte[] to create an ISO_8859_1 encoded string which they were able to do, but none suggested it. Gemini 2.5 pro This result is signifciantly improved. Use use of S