3 Strategies for Learning to Program with an AI Assistant

Some years back, my dad decided to buy a classic car. He found exactly what he wanted, an 80s-era Alfa Romeo Spyder, sold by a guy in New Jersey. The plan was to fly out there from his home in Michigan and drive the car back.

Then, after getting on the plane, somewhere on his way to the car, my dad lost his cell phone. Undeterred, he proceeded to complete the sale, gassed up, and made the approximately 10-hour drive home safely with no further issues. And, with no map.

Treat AI as an assistant, not a dependence.

I know plenty of people today that, faced without access to Google/Apple maps on their phone, would hesitate to drive across their hometown to a new restaurant, let alone 600 miles and four states. But my dad grew up without that technology, and he was able to use his knowledge of geography, U.S. highway systems, and past road trips to navigate home without even a paper atlas.

For students studying computer science today, or anyone relatively new to writing code, I think there’s a real risk of AI becoming a necessary crutch like Google Maps. So, how can you take advantage of an AI assistant without becoming beholden to it?

Use these strategies to learn to code with AI assistance.

Especially if you are early in your programming career, here are some strategies for learning to use AI without becoming dependent on it.

1) Write, compare, and rewrite.

This is a good strategy if you’re about to write code that is somewhat novel for you. First, try to write a solution all by yourself (aka make sure Copilot is turned off). Save that effort, then go ahead and ask the AI assistant to write the same bit of code for you.

Now, compare the results. How close was the AI solution to your own? If there are differences, try to understand what pros and cons there might be to both solutions. Learn what you can from the AI solution to make your own code better.

Finally, and this is the most important step: delete both your original solution and the AI’s code and then rewrite a solution from scratch. This time, incorporate what you learned from your initial write and compare. The repetition of writing the code over again will help you remember the same patterns later. And the next time you need to construct a similar bit of code, you can start with the AI version. By then, you’ll better understand how to tweak it to suit your needs.

2) Prompt, tweak, and reprompt.

Use this strategy to get better at asking the AI assistant for the right code. Unlike “write, compare, rewrite,” this is a strategy for when you need to generate code you’re already familiar with. First, prompt the AI for a bit of code that you need.

Now, evaluate that code and edit it to better suit your needs. Maybe you want to make it cleaner, rename variables, or use a more efficient algorithm. Treat it as if you’re doing a code review for a peer, and tweak it as much as makes sense. Save your modified code for reference.

Finally, re-prompt the AI to generate the same code for you again, but this time modify your prompt to try and get an output as close as possible to your tweaked version. Repeat this process until you can get exactly the code you want with a single prompt, or until you run against the limit of what the AI can do for you. Either way, you’ll learn a lot about how to instruct the AI more efficiently, and what kind of work you’ll still need to be able to do yourself.

3) Practice AITDD.

This is the most advanced strategy and should be used after you are proficient with the first two strategies. That is, you could write the code without the AI, and you know how to prompt the AI well for the code you want.

Test Driven Development is a great practice on its own to get better at writing code, because it forces you to think about the problem from a different angle, and gives you confidence that your solutions are correct. AI is the perfect companion for this programming practice.

For AITDD, you will prompt the AI to write code that will pass your tests. It will be tempting to ask the AI to write the tests for you as well. Don’t be tempted! It’s important that you are writing the tests. Use what you learned from “prompt, tweak, and reprompt” to compose tests that the AI can use to write the kind of code you’re looking for. The more tests you can write up front, the more context the AI will have along with your prompt to give you clean code that passes all your tests.

Working in this way, you’ll be training yourself to think through the hard questions of how code needs to be written and why, and leaving the what of it to the AI. It’s like trying to drive yourself cross-country without a map. If you know how to orient yourself and verify that you’re still headed in the right direction, the turn-by-turn directions become somewhat redundant.

Sorry, no hot takes here.

I recently wrote a post about encouraging the use of AI tools like ChatGPT in computer science education. I really believe these tools are extremely valuable and we should take advantage of them instead of resisting change.

At the same time, I believe there is real value in building strong foundational knowledge and adaptivity. I shared the story of my dad’s car-buying adventure to illustrate the advantage of not becoming too dependent on certain tools, or too abstracted from the basic mechanics of an action, to function outside the boundaries of those tools or when they break down.

The Alfa Romeo, back from New Jersey and freshly washed

What do you think of the threat or advantage of AI reliance in software development? Do you have strategies for using AI to best enable your own growth and effectiveness as a developer? I’d love to hear your thoughts in the comments.


Join the conversation

Your email address will not be published. Required fields are marked *