I have used AI for code generation. The results are quite a bit less than stunning. But clients get really excited when you claim that you are using AI.
My best results have been with a query similar to this:
"Example [class/method] in the [specify programming language] that does [specify desired action]"
Follow up with additional queries to revise the desired action. This works with Co-Pilot and with Claude.
I can generate complete applications with variations of this technique but they are not suitable for production use. They usually will not compile, let alone run until they are modified in various ways. They are lacking error checks and often contain major logic flaws.
You cannot just cut-and-paste this stuff. You must have a good understanding of the application domain. Testing and debugging remains the huge time sink that it has always been.
I have gotten best results by limiting the scope of a query to class or method generation. The art is in phrasing the queries.
AI codes tend to evolve to incomprehensible gibberish containing inexplicable artifacts if they are refactored too many times. Early results are the best ones.
My best results have been with a query similar to this:
"Example [class/method] in the [specify programming language] that does [specify desired action]"
That is basically my approach too. I ask the AI to generate code for simple, well-understood actions, e.g., "Create a code example written in JavaScript for Node that will send an SMS text message using the Twilio API"
This is a very common thing to do, with lots of examples online. The AI burped this out:
const twilio = require('twilio');
// Your Twilio account SID and auth token
const accountSid = 'YOUR_ACCOUNT_SID';
const authToken = 'YOUR_AUTH_TOKEN';
// Create a Twilio client
const client = new twilio(accountSid, authToken);
// Send the SMS
client.messages
.create({
body: 'Hello from Twilio!',
from: 'YOUR_TWILIO_PHONE_NUMBER',
to: 'RECIPIENT_PHONE_NUMBER'
})
.then(message => console.log(`Message sent. SID: ${message.sid}`))
.catch(error => console.error(`Error sending message: ${error.message}`));
It was exactly what I needed: Short, simple, and easy to verify.
AI code generation works best with short code snippets.