My Best AI Experience So Far
I've had mixed experiences with AI when it comes to programming. It generally isn't worth it. I can usually figure things out by looking at documentation. A place where I don't have waste energy vetting everything I find.
Of course, docs don't always have what you need. For example, I was trying to write some code to turn this:
Into this:
I kicked around the documentation for a while, but couldn't figure it out. Historically, I'd jump to a search engine looking for help. This time, I gave AI a chance. I used duck.ai. It's a free service from DuckDuckGo you can use without a login. I set it up to use "Claude Haiku 3.5", fed it a prompt with a concise code example, and click the button. After a few seconds, it spit out working code that did just what I want.
I was legit impressed.
The Use Case
I'd never prompted an AI with a code example before. My inputs were always along the lines of "How do I do THING in LANGUAGE?" I'd try the response in whatever I was working on. The success rate sucked.
This first experience with a code based prompt made me raise an eyebrow. I'm not interested in installing AI tools directly on my machine or pointing them at a full code base. But, if I can make little example snippets and get responses about specific techniques, I'm into that.
-a
Endnotes
This is my ideal scenario right now. Let me write up a question the same way would for Stack Overflow: A concise question with an example trimmed down to the least code possible.
Then, show me the most concise bit of code that does what I need. Something is quick and easy for me to test.
Even better would be an upgraded experience where it runs the code and shows the output for verification.
If you're interested in the specifics, here's the prompt I used:
Prompt for Claude Haiku
How do I update this rust code:
```
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
struct Item {
id: String,
name: String,
}
fn main() {
let input = r#"{ "id": "1234", "name": "alfa" }"#;
let item = ingest_json(input);
let output = generate_output(&item);
println!("{}", output);
}
fn ingest_json(input: &str) -> Item {
serde_json::from_str(input).unwrap()
}
fn generate_output(data: &Item) -> String {
serde_json::to_string_pretty(data).unwrap()
}
```
So that it outputs this:
```
{ "1234": "alfa" }
```
Instead of:
```
{
"id": "1234",
"name": "alfa"
}
```
This is the code it provided. It does exactly what I need. It's also clear to read and made minimal changes to what I sent in originally.
use ;
use HashMap;
I still have concerns about AIs impact on basically everything.