Posts

Showing posts from July, 2025

Improving the prompt to the AI to get better code

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 co...

Asking multiple AI to optimise the same code

As different AIs are implemented differently, they don't all provide the same answer, nor do they consistently outperform one another. The best approach is to use multiple AI and pick the one you like best. My goal here is not to declare a winner based on one example, but instead to show the variety of answers you can get with different AI. I asked each AI to Suggest how to implement this more optimally 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) { ...