AI - How to use it for coding and learning

Why use AI in Programming

Programming has always been linked to the programmer's knowledge and skills to solve problems. In the journey of learning to program, we face common challenges: "Where to start?" "Am I doing it right?" "I don't know how to fix this error."

While we have resources like Google and StackOverflow, how can we further boost our learning and work more efficiently and productively? The answer lies in leveraging an AI assistant.

Benefits of AI Assistants in Programming

An AI assistant is a tool that, through artificial intelligence and the information we provide, helps us increase our productivity. Here are some benefits:

  • Easier Code Understanding: It can assist in understanding code and concepts with detailed explanations and simplifying complex ideas, contributing to deeper and more effective learning.

  • Descriptive Code Generation: It transforms natural language descriptions into functional code, helping to translate ideas into implementations and strengthening understanding.

  • Refactoring for Clarity: It can help improve code structure to make it more understandable and maintainable, fostering orderly and precise coding.

  • Guided Error Resolution is very useful for identifying and solving errors, offering guidance to correct problems, and enhancing debugging skills.

  • Smart Autocompletion: It completes code intelligently, anticipates and suggests necessary snippets for specific tasks, and speeds up writing.

AI Assistants

These tools allow you to ask questions and hold conversations to get help:


How to use AI

There are different ways to use AI to help your learning and coding process.

  1. Coding Mentor with ChatGPT

  2. Start a Project with ChatGPT

  3. Use VS Code AI Extensions

  4. Use them to reduce information overload

  5. Create relevant examples

1. Coding Mentor

You can prompt ChatGPT to be your Coding Mentor. The video below explains how to do that.

2. Start a Project with AI

Starting a project can seem intimidating. But AI is here to help. Watch this video to find out how. The video, in general, is great and gives you more ideas on how AI can help. How it supports starting a project starts at the minute: 11:01.

3. Support in VS Code - VSCode Extensions

ChatGPT and other AI models are great supporters. However, in VS Code, you can integrate other tools that help you refactor the code, explain code, and support you hands-on while coding. Integrate these tools directly into your code editor to autocomplete code or add functionalities:

You don't need to try them all. Choose one or two tools that fit your needs—they're meant to support, not replace, your learning. You’re in charge of your learning journey!

4. Use Them to Reduce Information Overload

When starting new projects or working with unfamiliar technologies, it is common to encounter a lot of information and even feel overwhelmed. The mentioned tools can be very useful for overcoming this challenge.

Let's see how an AI assistant can be beneficial in this situation:

Message: I am learning web development with JavaScript, HTML, and CSS. I need a scheme to help me understand what unit testing is, what it is for, and how it is used. Consider that I don't know anything, explain it to me simply and clearly.

Click to view ChatGPT's response

Sure! Let's start by understanding what unit testing is and why it is important in web development. What are unit tests? Unit tests are pieces of code designed to verify that individual units of your application work as expected. A "unit" in this context refers to the smallest unit of code, such as a function or method. Why are they important? Early error detection: Unit tests allow you to identify and correct errors at an early stage of development, making the process easier and faster. Facilitate maintenance: When you make changes to your code, unit tests give you confidence by ensuring that existing functions continue to work as expected. Improve code quality: By writing unit tests, you are documenting how each part of your code is supposed to work. This makes it easier for other developers to understand and collaborate on your project. How are unit tests used?

There are specific tools for performing unit tests in JavaScript. One of the most popular is Jest. Below, I will give you a basic outline of how you could structure your tests...

If the result doesn't meet your expectations, consider exploring another perspective that aligns better with your way of thinking, for example:

Message: I'm not very clear, can you use a metaphor to help me understand it better?

Click to view Gemini's response

Of course. Imagine you are building a house. Before you start building it, you will need to design the plans. The plans are a set of drawings that show how the house will be. The plans help you make sure the house is well-designed and that all the elements fit together.Unit tests are like the plans of a house. They help you make sure that your code is well-designed and that all the elements work correctly.In the case of unit tests, the units of code are like the bricks used to build the house. Each brick has to be strong and well-placed for the house to be strong. Unit tests check that each unit of code works correctly, which helps ensure that the application is robust.Here's a more concrete metaphor for unit tests in JavaScript:Imagine you are writing a function that adds two numbers. The function could be like a calculator. Unit tests would be like the people who use the calculator.If you write a unit test that checks that the function adds two numbers correctly, you are making sure that the calculator works correctly. If the unit test fails, it means that the calculator has an error.The more unit tests you write, the more confident you will be that your code works correctly.

I hope these metaphors help you understand unit tests better.

Finally, you can strengthen your understanding by asking questions that confirm what you have learned.

Message: Can you confirm if I am correct? I understand that tests aim to ensure the quality of my code using a tool called Jest.

Click to view ChatGPT's response

Exactly! You have captured the idea correctly. Unit tests, in this case using Jest as a tool, have the main objective of ensuring the quality of your code. Jest allows you to write and run tests efficiently, helping you quickly identify possible errors or issues in your code.By writing unit tests, you are validating that each individual unit of your code (such as functions or methods) produces the expected results for different situations. This not only helps to find errors early in the development process but also provides live documentation on how your code is supposed to behave.

So, in summary, yes, unit tests with Jest are an excellent tool to improve the quality and reliability of your code in web development. Keep exploring and practicing!

You also have the option to request questions you can answer to consolidate and reinforce your learning.

Message: Can you give me 5 questions to answer to validate if I understood what unit tests are?

Click to view Gemini's response

Sure, here are 5 questions to help you validate your understanding of unit tests:What is a unit of code?What are unit tests for?How are unit tests used?What is a test environment?What are some tips for writing unit tests?


5. Create Relevant Examples for Your Specific Situation

For example, if you are immersed in the Dataverse project and encounter challenges starting the filtering section, you might consider the following:

Message: I am learning JS and want to know how to filter even numbers. Can you give me an example? Explain how it works.

Click to view ChatGPT's response

Sure! I can help you with that. You can use the filter method along with a callback function that evaluates whether each element in the array is an even number. Here is an example:// Array of numbersconst numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];// Callback function to filter even numbersconst isEvenNumber = number => number % 2 === 0;// Use the filter method to get only the even numbersconst evenNumbers = numbers.filter(isEvenNumber);// Show the resultconsole.log("Even numbers:", evenNumbers);Explanation:Define the array of numbers: We create an array called numbers with some numbers.Callback function (isEvenNumber): We create a function called isEvenNumber that takes a number as an argument and returns true if the number is even (is divisible by 2) and false otherwise.Filter method: We use the filter method of the numbers array, passing the isEvenNumber callback function as an argument. This method creates a new array that contains only the elements for which the callback function returns true (in this case, the even numbers).Show the result: We print the resulting array, which contains only the even numbers.

Explore your curiosity and ask questions that allow you to delve deeper into the topic.

Message: You mention something called callback, what is it?

Click to view ChatGPT's response

In programming, a "callback" is a function that is passed as an argument to another function and that will be executed after the main function has finished executing. In other words, the callback is a function that is "

Last updated