ChatGPT Crash Course For Developers
Apr 13, 2023I know that you've seen a ton of content on ChatGPT lately. I actually wanted to wait a while because instead of just whipping up a video and article using stuff I researched on the Internet, I wanted to use ChatGPT for a while before creating content on it and then really explore and show some of the practical uses for developers. The YouTube video to go along with this article can be viewed here.
I've used it daily for the past few months and it has really helped with my productivity and has been not only a great learning tool, but a very helpful coding partner. In this article I want to give you 10 different things that you can use ChatGPT for as a developer and I'm not just going to tell you about them, I'm going to show you how to do it and give you prompt examples. This will help you add ChatGPT to your workflow and I guarantee it will increase your productivity.
What Is ChatGPT?
Before we get into using ChatGPT as a developer, I want to talk a little bit about what it is and how it works. ChatGPT is a chatbot released in November of 2022 that uses AI to answer your questions. It's built on GPT-3
and now has the option to use GPT-4
. GPT stands for Generative Pre-trained Transformer
. It is a language model developed by a company called OpenAI
that uses deep learning to generate natural language text. It has been trained on a massive dataset of text from the internet, which allows it to generate responses to a wide range of prompts and questions.
ChatGPT is capable of understanding and responding to natural language queries in a way that is similar to how humans communicate with each other. It has been used for a variety of applications, including language translation, content generation, and even creative writing.
The extent to what you can do with ChatGPT is limited only by your imagination. There's no way that I could come close to covering everything even if I could make a 1000 hour long video. So I'm going to focus on the things that I've found to be the most useful when it comes to writing and debugging code and doing other things related to programming.
What Is OpenAI?
OpenAI an independent organization with a team of researchers and engineers working on various projects related to AI. It was initially founded in 2015 by a few people including Elon Musk. Although Musk left, I believe in 2018 due to conflicts of interest with his other companies. OpenAI has a lot of funding and are one of the most well known AI research companies in the world. In 2019, Microsoft invested $1 billion in OpenAI, which gave it exclusive access to OpenAI's technology for use in its Azure cloud computing platform. Bing and Microsoft Search are also using OpenAI's GPT-3 technology to improve their search results.
Is ChatGPT Free?
The basic version of ChatGPT is completely free. You just need to register for an OpenAI account and then you can start using it. They do offer a paid version called ChatGPT Plus
, which gives you unlimited access and no blackout periods. With the free version, it's common to see errors where ChatGPT is unable to answer your question. So the free version is limited. I would definitely suggest getting the paid version if you plan on using it a lot. I got it when it first came out. It's $20 per month right now.
Does ChatGPT Give Wrong Answers?
The short answer to this is yes it can. It's not perfect, so if you're using it for help for an article or something where it is really important that your information is accurate, you should really double check and verify the information that you get from ChatGPT. ChatGPT is also not connected to the internet and is unable to determine the current date and the training data cutoff is 2021.
Do you need to learn ChatGPT as a developer?
I wouldn't say that you "need" to know how to use ChatGPT at the moment. However, it is definitely a good idea because AI in general is the biggest thing that will be affecting developers in the next 10 years. So if you want to stay relevant, you need to start learning how to use AI. I'm not saying that you need to be a machine learning expert, but you should know how to use it.
Now you might be saying, what's to learn? I type in a question and it answers me. Well, yes, that's true, but there's actually a bit more to it than that. For example, you should know what it's capable of when it comes to help with debugging, generating data, creating documentation and so on. Those are the things that I want to go over in this video.
You need to know how to phrase your questions properly in order to get the best results. You also need to know how to interpret the responses that you get from ChatGPT. Sometimes the responses are straightforward and easy to understand, but other times they can be a bit more complex and require some additional research or knowledge to fully comprehend.
Natural Language Programming
I probably wouldn't have said this 5 or even 2 or 3 years ago, but I truly believe that in the near future, learning how to "prompt" ChatGPT or other AI tools will be a necessary skill for developers and at some point, will be the main way that developers will be able to create software. Just like the programming languages we use have evolved over time, from low-level assembly language to higher-level languages like C and C++ and then even higher level languages like Python and JavaScript. See the pattern here?
Will It Take Programming Jobs?
What would any article about AI be without the question of will it take our jobs. I can't answer the question of whether or not AI will take our jobs, but I can tell you that it will definitely change the way that we work. I think it will change the landscape of jobs for sure. We may have "Prompt Engineers" or "AI Engineers" in the future. I don't know, but I do know that it's going to be a lot different than it is today. Not even just in tech, but jobs in general. As far as the fear mongering goes, I think that's just a bunch of hype. That kind of stuff gets views because fear sells. Try not to put too much stock into it. You can't control the future, so just it to your advantage right now.
ChatGPT & Open AI APIs
As a developer, there are some really cool tools that we can use to build applications that integrate with ChatGPT. You just need to create an OpenAI account, get an API key and then you can start using their APIs. Some of the APIs included are Completion API
, Search API
, Classification API
, Summarization API
, Translation API
, Dall-E API
, Image API
, Text API
, Video API
, Audio API
, File API
, Code API
, Knowledge API
. I have a couple recent video projects on my channel using the completions API
and the Dall-E API
. Sometimes people get confused when we talk about learning machine language and AI to create tools like ChatGPT and then using those tools and APIs to create other types of projects. Using the Dall-e API to create an image generator is not the same as creating a machine learning algorithm from scratch. They aren't even in the same wheelhouse. I'm way too dumb to create a machine learning algorithm in python. However, I can create web apps that use the APIs provided.
The ChatGPT Interface
Now, let's start using the app. The ChatGPT interface is very simple.
At the top/middle, you have your model. The default is GPT-3.5
. If you are a plus
user, you have access to GPT-4
, which is even more advanced, however it is slower.
At the bottom, you have your input box where you type your question/prompt and then above that will be where your output area will give your answers.
On the sidebar, you have all of your open chats. When you create a new chat, it will be added to the sidebar. This is really helpful because you can have multiple chats open at the same time. You can also save your chats and come back to them later. If you click on the chat, you will be able to rename it or delete it.
At the bottom of the sidebar are som more options. From here you can clear all of your conversations. You can also view your current plan and change from dark to light theme in the settings.
How To Use ChatGPT As A Developer
Now that we know what ChatGPT is and how it works, let's look at some of the different ways that we can use it as a developer.
1. General Learning Tool
We all have a preference when it comes to learning something new. Whether that's video tutorials, articles, books, documentation, other people's code and just people in general. These are all great ways to learn something new or to learn more about something you already know. Well ChatGPT is something else that we can add to the list. In all honesty, this one is that threatens my job as an educator. Although I think it's more of a supplement to what I do.
The thing that makes ChatGPT different from most other learning methods is that it's dynamic. With a book or a video, you have the content that's there and that's that. But with ChatGPT, you can ask it specific questions and get personalized answers based on your unique context and knowledge level. It can help you understand complex concepts in a simpler way, or clarify details you might be confused about. Additionally, it can help you discover new areas of interest that you might not have thought about before. I think the closest learning method to ChatGPT is the one-on-one tutoring or mentoring, but even that is different because you're limited to the time you have with the tutor and usually tutors or mentors are not cheap. You are also limited to their knowledge and experience.
Example
When you want to start learning about something, be clear on what you want to learn. In fact, it's a good idea to ask for the steps, so that you have a clear idea of what you need to do. For example, if you want to learn how to use the fetch
API in JavaScript, you can ask ChatGPT questions like:
I would like to learn the fetch api. What are the steps that I should take?
ChatGPT will give you an extremely well written list of what you should do and the order in which you should do it. This chat will stay here until you delete it, so you can always reference it, but you could also copy and paste it somewhere else.
Next, it's a good idea to ask for any references or resources that you can use to learn more about the topic. For example, you can ask ChatGPT:
What are some good resources to learn the fetch API?
Again, you will get a nice list of resources that you can use to learn more about the topic. The only issue that I have with this is that Traversy Media was not included in the list. I'm kidding. Kind of 😂.
From here, I would ask to start with the first suggestion. Just to show you that it saves all of the context, I will just write:
Let's start with the first step
I didn't have to remind it of what the first step was because it remembered.
So you can see that it's a very good learning tool. It is dynamic and customized to be exactly what you need.
2. Get Feedback On Your Code
As developers, we all need feedback on our code. It helps to get a second pair of eyes on it and get advice on how to improve it. ChatGPT can be a great resource for this. You can ask it specific questions about your code, or show it a section of your code and ask for feedback. It can also help you identify potential bugs or inefficiencies in your code.
Example
Let's say that you have a piece of code that you are unsure about or maybe you just want to know if there is a better way to do it.
I will ask for feedback on some code that I know could be written better.
Simply ask,
Can you give me some feedback on this code?
Then paste your code in the input box.
<a href="/">Home</a>
<a href="/profile">Profile</a>
<a href="/search">Search</a>
<script>
function handleClick(e) {
history.pushState(null, null, this.href);
fancyPageLoad(this.href);
e.preventDefault();
}
for (let link of document.querySelectorAll('a[href]')) {
link.addEventListener('click', handleClick);
}
// ...listen for added/removed links using MutationObserver...
</script>
As you can see, it came up with a list of suggestions. They are pretty good suggestions.
It also gave me an example of how I could improve the code.
3. Solving Specific Problems
We talked about using ChatGPT as an overall learning tool, but there are times when we need a solution to a specific problem. In the past most of us used StackOverflow for this and it works in many cases, especially something that is not that difficult. For more complex stuff, it takes a lot of time searching and in many cases you end up with the exact question you're looking for and you scroll down and there's not a single answer, and you want to smash your monitor. Every developer has been there. Well with ChatGPT, you may not get what you need right away, but it can help you get there. It can help you understand the problem better and give you ideas on how to solve it. It's also usually quicker than searching on StackOverflow.
Example
Let's ask how to build a web scraper in Python that extracts data from a website and saves it to a CSV file.
How can I build a web scraper in Python that extracts data from a website and saves it to a CSV file?
Not only does it give me the code, but it explains exactly what the code is doing.
On a side note, as helpful as this is, it does worry me for the future of developers. What is to stop them from being lazy and just asking ChatGPT for the code instead of learning how to do it themselves? I think that educators really need to stress the importance of learning how to do things yourself and not just copy and paste code.
4. Brainstorming
When we're starting a new project, or we're stuck on a problem, it can be helpful to bounce ideas off of someone. ChatGPT can be that someone. You can ask it open-ended questions or provide it with some context about what you're working on and it can help you brainstorm new ideas or solutions to problems. I've done this countless times for my own projects, tutorials and courses.
Example
Let's say you just learned about the Geolocation API
, and you want to use it in a real-world project. Let's ask for some ideas.
I need some ideas for a web app that uses the geolocation API
From here you could say
I like the idea of a weather app
it will go on to help you get started with the app.
5. Generating Sample Data
This one is huge for me. Often times, I'll need a bunch of sample data for a project and I hate trying to figure out which type of data to use and then thinking of all the fields and values and then typing it all out. We can get ideas on data as far as the type of data and the fields and values from ChatGPT. It can also help us generate the data itself. I've used this for my own projects and for my courses. It's a huge time saver. And it can be formatted in any way that you can think of including JSON, CSV, XML, YAML, etc. You may even just want some HTML. An unordered list or a table with dummy data. ChatGPT is great for this.
Example
In my Node.js API course, we created an API for coding bootcamps. I had to think of and manually type out all of the data for the bootcamps. It was a pain. I could now just use the following prompt to get the data.
I need some sample data for a project. I need a JSON array of coding bootcamp objects with at least 10 fields.
And of course, if there was something that I didn't like, I could just ask for something else.
I don't like the name of the bootcamps. Can you give me some new names? and also leave out the founder
We used to need websites like Mockaroo for this, but now we can just use ChatGPT.
6. Create Documentation
Documentation is important for any project, but it can be time-consuming to write. ChatGPT can help you generate documentation by providing you with templates or suggestions on what to include in your documentation. If you have an API, you can provide the code or the structure of routes and resources and it will generate documentation for you.
Example
I found an old Laravel API that I create a while back. We're going to ask ChatGPT to generate documentation for it.
Can you generate the documentation for this project - https://github.com/bradtraversy/larticles_api
It gives me documentation in yaml
Let's ask it for the documentation in markdown
Can you generate the documentation for this project in markdown?
I'm sorry, but that is just amazing.
7. Error Messages
There have been countless times where I've gotten crazy errors and stack traces that I don't understand and instead of Googling like we always have had to do, I pop the error or logs into the prompt and ChatGPT will give me a detailed explanation of what the error means and how to fix it. It's a huge time saver. In fact, I have a modded Minecraft server and it was having chunk loading issues and I was getting errors that I didn't understand. Im not a Java developer. I popped the logs into ChatGPT and it told me which mod was causing the issue and how to disable it.
Example
Let's say you're getting an error that you don't understand. You can just paste it into the prompt along with the code and you will often get the answer the first time you ask.
This is a simple capital search project from a past tutorial. I added some curly braces around the states
variable to throw an error. Let's paste in the code and the error:
I'm getting this error when I try to run my app. Can you explain it to me? main.js:10 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'filter')
at searchStates (main.js:10:24)
const search = document.getElementById('search');
const matchList = document.getElementById('match-list');
const searchStates = async (searchText) => {
const res = await fetch('../data/states.json');
const { states } = await res.json(); // I added curly braces to throw an error
let matches = states.filter((state) => {
const regex = new RegExp(`^${searchText}`, 'gi');
return state.name.match(regex) || state.abbr.match(regex);
});
if (searchText.length === 0) {
matches = [];
matchList.innerHTML = '';
}
outputHtml(matches);
};
const outputHtml = (matches) => {
if (matches.length > 0) {
const html = matches
.map(
(match) => `
<div class="card card-body mb-1">
<h4>${match.name} (${match.abbr}) <span class="text-primary">${match.capital}</span></h4>
<small>Lat: ${match.lat} / Long: ${match.long}</small>
</div>
`
)
.join('');
matchList.innerHTML = html;
}
};
search.addEventListener('input', () => searchStates(search.value));
It tells me exactly what the issue is and how to fix it. I know this is a simple one, so you may have to conversate a bit with ChatGPT to get it to understand what you're asking, but it's still a huge time saver.
8. Create Tests
I've never really gotten deep into test-driven development, mainly because I don't work on huge projects with multiple developers and they're projects that I feel don't really need testing and it takes up too much time. However, ChatGPT can help you generate tests for your code. It can also help me generate test data. I've tried this recently for a project I'm working on and it worked great.
Example
Let's ask it to give us a Jest
test for the code above. Just remove the curly braces around states
to fix the issue.
Can you generate a Jest test for this code?
Absolutely amazing.
9. Natural Language Programming
ChatGPT can be used to write code using natural language. This means that instead of writing code in a specific programming language, you can describe what you want the code to do in plain English and ChatGPT will generate the code for you. This can be especially helpful for beginners who may not yet be familiar with a specific programming language. I honestly think that in the future, this will replace traditional programming. I think you'll still need to learn programming languages, but the way we go about writing that code will change drastically as AI becomes more advanced.
Example
Let's create a REST API with the RUST programming language. I am somewhat familiar with REST but I could not create this without looking in the documentation and taking a few hours to study, but I can describe what I want the API to do and ChatGPT will generate the code for me.
I need a REST API written in Rust. It should have products with an id, name, description and category_id. The category_id should have a relationship with another resource called categories that has an id and name. Let's use SQLite as a database. Use any frameworks and libraries that you see fit.
There you go. It's most likely not perfect, but it's a good start. I could probably get this working with a little tweaking. That tweaking
is going to be a necessary part of the future of programming. We're going to have to learn how to tweak code that AI generates for us. I think that's a good thing. It will allow us to focus on the more important parts of programming and let AI handle the boring stuff.
10. Creating UIs
I know a lot of fantastic web developers when it comes to business logic and backend stuff, but when it comes to the front end, they're not so great. ChatGPT can help you create UIs by providing you with templates or suggestions on what to include in your UI. This is great if you're not the best at design or if you just don't have the time to design a UI.
Example
Let's create a UI for a simple blog.
I need the html and css for the homepage of a blog with a navbar that has a logo area with the text "My Blog", a hero area with some dummy text and a background image from unsplash and 3 cards with some sample posts. Make the color scheme have some light blues and greens
This is what I got:
It definitely needs some work and I would have to go back and forth with ChatGPT to get it to look exactly how I want it to, but it's a great start.
So that brings me to my final point that is really important. This is almost magic, but it isn't. You can't expect perfection on the first prompt. You need to work with it as if it were a coding partner. These are ten different uses for programmers, but the possibilities are endless. I think this is going to be a huge part of the future of programming, including future web development courses and tutorials, and I'm excited to see where it goes.
Stay connected with news and updates!
Join our mailing list to receive the latest news and updates from our team.
Don't worry, your information will not be shared.
We hate SPAM. We will never sell your information, for any reason.