How to learn a programming language using AI

By Khalid Abuhakmeh

Whether you’re new to software development or you have decades of experience, there’s always room to learn something new. The TIOBE Index tracks the top 50 most popular programming languages, with many ecosystems presenting opportunities for career advancement and lateral shifts. Given the breadth of technologies available, it can be challenging to find the time to learn a new skill and to do it effectively.

Recently, I have been attempting to learn the Rust language, a type-safe language built with performance, reliability, and productivity in mind. In doing so, I have learned a few techniques for using AI coding assistants that I want to share with you to improve your learning experience.

By the end of this post, you should have a few new AI-based skills that you can apply during your learning journey and accelerate toward your goals. In the scope of this article, when I say AI, I mean the AI-powered coding assistants based on large language models, such as Amazon Q Developer (formerly CodeWhisperer), GitHub Copilot, and JetBrains AI Assistant. You can apply all of the tips below to the tool of your choice.

Be suspicious of parametric knowledge

“Parametric knowledge” is information stored within the model during training. The encoded data is why AI can often respond quickly with accurate information. Still, as you’ve likely seen in the news, AI can get the answer spectacularly wrong at other times.

What does this mean for us as users? While these systems can be helpful, they have limits constrained by the time and resources required to collect data and train the model. For example, OpenAI has trained the ChatGPT 4 Turbo model on information up to December 2023, and the data set’s contents are unknown. From a user’s perspective, there’s uncertainty about whether “complete” knowledge exists within any particular model and why sometimes we may be underwhelmed by its responses.

Being mindful of the cutoff date for the data set can help you better understand and process the responses from your AI chat sessions. As a consumer looking for a service to purchase, researching a provider’s data-gathering practices and training process can lead to a more satisfying experience.

While AI can be generally helpful, verified human sources of knowledge will still be the most valuable during any learning process. That’s not to say that the AI systems are always wrong, but you need to get into the habit of questioning whether the information you’re consuming is correct. An additional reason to be cautious is that the creators of these systems trained them to be helpful above all else. Sometimes they can be “too helpful,” hallucinating ideas and concepts that may not exist.

In summary, it takes “real intelligence” to understand when AI makes mistakes.

Read code and prompt for explanation

The open-source software movement has provided every learning programmer with easy access to production code. Open-source code bases offer an excellent opportunity to see how the professionals write and to pick up language idioms, tricks, and more. But reading an unfamiliar language can be daunting and downright confusing without a frame of reference or basic understanding.

A technique I’ve been using is finding code on the popular code-sharing site GitHub for particular languages and pasting it into an AI chat session, along with the prompts, “Please explain this code,” and “please list the important language concepts happening within this code block.”

A template for this prompt might look something like this.

Please explain the following code

```rust

// rust code goes here

```

Also, list the important language concepts from the description in a bulleted list so I may do more research.

The resulting list of topics is an excellent way to focus my learning on what is essential at the moment rather than trying to absorb an entire library’s worth of information at once.

The JetBrains AI Assistant will let you store prompt templates for reuse, which is incredibly useful as you jump between different projects.

Prompt for verbose inline comments

A wall of code can be very intimidating when you still haven’t fully learned the syntax or semantics of a language. Using the prompt “comment each line” is a quick and easy way to get a general idea of what an application may be doing.

With the JetBrains AI Assistant, you can also get a Diff view of the changes in a side-by-side or unified view. The view allows you to quickly review the changes and choose to accept or reject them.

Play with different options

Learning any topic involves experimenting and, more importantly, playing with learned concepts. This is essential to finding a working solution and understanding when to try a different approach. With AI, trying out variant implementations has never been more straightforward.

Here’s a prompt I’ve used to discover features in the Rust language that allow me to follow up and do additional research.

Given the following API, show me three different implementations

```rust

fn add(x: i32, y:i3) -> i:32 {

// implementation goes here

}

```

Remember, this is about learning, so the APIs don’t have to be particularly sophisticated. Playing with ideas allows you to uncover different learning paths outside the AI chat session. The technique is excellent, especially compared to traditional topic hunting, which may have limits based on your understanding of a particular subject.

Some tools, like Amazon Q Developer, offer options inline, allowing you to cycle through examples without leaving the context of your editor. Pressing the right and left arrow keys lets you move between options until you find one you like.

More context is always better

I mentioned the embedded information limitations of LLMs above. Keep in mind that, where these services may lack information, you are in a perfect position to provide it. But you need to go about it the right way.

The modern internet search experience has trained us to ask snappy keyword-based questions in text boxes. Search-style queries are a common mistake I see many newcomers to AI make, and it can leave them underwhelmed with the results. Thinking about AI chat sessions as “search” is a bad habit to apply when using AI assistants, as creators of LLMs built them to predict what you may want.

The best way to get better predictions is to be as lengthy and explicit as possible.

An approach that works well is example-based prompting. The more examples you can provide, the better your results will be. Here’s a template prompt that could help you discover new ideas in your learning journey.

Given the following three examples, what would an implementation for <X> look like?

example 1:

```

```

example 2:

```

```

example 3:

```

```

The data you enter into a chat session provides the context needed to achieve your desired outcome. Don’t be afraid to correct or add more context as you go. The more, the better, as the model has more information on which to base responses.

To keep the conversation going and to increase the chat session context, Amazon Q Developer gives you a set of natural follow-up questions to keep you engaged in the learning process.

Peek at code completion

Most AI services offer multiline code completion. While it may be tempting to accept all the options presented in the editor, this often impedes my progress toward learning. Instead, I like to start by creating a code comment that indicates my goal.

// TODO: create a match expression to process the different message variants

In the following figure, we see GitHub Copilot offering to complete my statement. It looks good at first glance, but I must pause to digest the option and whether it fulfills my intention. Before pressing Tab, which is very tempting, I need to stop. Why?

The reason is to check whether the code is something I can read and process with my current skill set. If it is, then I’m making progress. If it is not, then I should take time to understand where the gaps in my knowledge exist. You should never accept code you do not fully comprehend into your code base.

Note that you can configure this feature to be less intrusive and only display completions on-demand to reduce the cognitive load of switching between writing and reading code.

Explain errors and find solutions

With every programming stack, you will run into compilation and runtime errors. Some of these errors can be cryptic. If you’re struggling to understand why your application is failing, use an AI assistant chat session to explain the issue, find where it occurs, and propose a solution.

What exactly is the problem here in my Rust backtrace? Reduce the response to the file and line and explanation of the error and propose a solution.

```

```

Here is an example of using this prompt to understand what happened in my Rust backtrace.

Share ideas

While moving from one topic to another with AI chat sessions may feel natural, it is always good to slow down and recontextualize your newly found knowledge with others. Once I’ve learned a new concept and created a working sample, I share it with other learners and experts to get valuable feedback. Remember, AI can only be helpful regarding your requests, whereas fellow humans will enrich you with their lived experience and predict potential pitfalls you may be oblivious about.

Social media platforms are a great place to share screenshots, code samples, and ideas and receive valuable feedback that you can incorporate into future AI chat sessions.

Summarize the chat

And here’s a tip for folks (like me) who may not be good at taking notes but might want to recall their previous day’s efforts. When your neurons are firing at the end of a long learning session, ask your current chat session to summarize all your questions and list a single-sentence answer for each question.

Given what we’ve chatted about, list all the questions and a single-sentence summary of each answer.

The response is an excellent quick reference guide for your next learning session. It also makes a great blog post where you can practice sharing your ideas and learning experiences with others.

Learn faster with AI

I hope you found these tips helpful as you use AI tools to learn faster and more effectively. These tools are about enabling you and helping you achieve the goals you set for yourself. I’ve found them helpful in forming new thoughts and exploring ones I didn’t know existed.

Most importantly, they allowed me to connect with communities of other individuals who broaden my knowledge. If you have any other tips for accelerating your learning using AI, please share your thoughts and tips with me and others.

Khalid Abuhakmeh is a software developer with 16 years of coding experience, specializing in Microsoft .NET technologies. Throughout his career, he has held various software developer titles, from junior developer to director of software development. Currently, he works as a developer advocate for JetBrains, focusing on the .NET ecosystem.

New Tech Forum provides a venue for technology leaders—including vendors and other outside contributors—to explore and discuss emerging enterprise technology in unprecedented depth and breadth. The selection is subjective, based on our pick of the technologies we believe to be important and of greatest interest to InfoWorld readers. InfoWorld does not accept marketing collateral for publication and reserves the right to edit all contributed content. Send all inquiries to doug_dineley@foundryco.com.

© Info World