AI is teaching my nine year old to code

AI is teaching my nine year old to code

My nine year old daughter, Emma, wrote her first Python code this weekend.

Years ago I wrote a post about how I learned to code on the TRS-80, and lamented that my introduction to coding was so much more accessible than what kids have today. I cannot overstate how much better the learn-to-code experience has become thanks to the assistive AI technologies that have come on the scene in over the last 12 months.

We're using Cursor, "The AI-first code editor." It's a fork of VS Code with a bunch of AI-assisted features that drastically reduce the friction and frustration of coding.

Quick example: no syntax errors.

My friend Rob Spectre says of programming that, "the distance between feeling like an idiot or genius is one character wide." Many novice developers get pushed away by the sheer amount of head-banging-against-the wall that occurs when you lack the intuition/experience to get the characters to line up juuuuuust right.

Fancy autocomplete, syntax highlighting and extensions like error lens catch 95% of the silly errors before you run your code.

Emma and I are building on the Claude API.

It's funny, she's actually spent a lot of time using the web-based versions of ChatGPT and Claude. Specifically, she's using them to help her write a book, which now clocks in at ~180 pages. The app we're building lets her chat with one of the characters – Lillis – from her book and go on adventures together through the world she's created.

When we set out to build this app, I instinctively reached for OpenAI APIs because that's what I've used the most, and she quickly said, "No, I want to use Claude."

"Oh... GPT-4's not good enough for you anymore?"

"It's not that I think Claude is better, but that it's better for this job."

I swell with pride that my nine year old daughter already has opinions on LLM APIs. LLM APIs are the highest juice-to-squeeze ratio you'll ever find in coding. It's an absolutely magical first-time-coding experience. The first time I ever wrote code, back in 1986, I got back "HELLO WORLD" – and that was enough to hook me for life. Emma's getting a passably human conversation with a character crafted from her imagination.

We played with this idea a year ago, but back then she was looking over my shoulder, watching me write code on my machine. This time, Emma's hands were typing on her own computer. (I did setup the virtual environment and API keys). I sit next to her and tell her what to type, and fancy autocomplete takes care of all the spellings, indentations, punctuation, etc. Within ten minutes, we had our app running in the terminal.

The app was simple: a while loop takes an an input() from the user, feeds it to Claude, prints the result, and repeats. It's basically the Hello World with ChatCompletion which I documented on this blog over a year ago, but with Claude swapped in for OpenAI. It's about 20 lines of code.

This worked really well, but the conversation restarted every time the program stopped. Lillis had no memory. Emma asks the integrated chat how she can save the messages. It gives her a few sentences of strategy, and writes a few lines to save and load the messages to a JSON file.

Boom, she just learned about file handling.

Now the Python script is working, but she wants to make her app prettier than typing in a terminal. Streamlit seems like the right choice to quickly move an LLM app to a web-based interface, but I haven't used it before, so I struggle for five minutes trying to steer from over her shoulder.

Then I give up and say, "just ask chat to change your app into a Streamlit app."

Her Streamlit app runs on the first try.

We've now gone from Hello World in the terminal to a well-styled web app with persistent memory in under an hour. And my hands haven't touched the keyboard.

My wife, Rachel, walks by. Emma beams, "Mom, look, I made this. I MADE IT!"

I can't describe the excited look of accomplishment and possibility on her face, but if you're reading this, you've probably felt it yourself. She just discovered a new superpower that she didn't have an hour ago. She can manifest ideas into the real world. The world looks different now.

Of course, as soon as her app ran, Emma had a punchlist of ways to improve it. Copy and style changes, mostly. Unfortunately, it's time to put her younger sister to bed, so I tell Emma, "I'll be back in a bit, just ask chat the questions you'd ask me."

Twenty minutes later, I exit the dark room and find Emma waiting for me at the door.

"DAD! I changed the font! I got it to work! It took six tries."

Then, trying to come up with the words to express this new experience of struggling and iterating to finally get it to work, "... it's not that I enjoyed doing it six times, but the feeling I got after it worked was.... AMAZING!"

There has never been a better time to learn how to code.