As a large language model, ChatGPT is all about text. And that text includes—lucky for you!—code. It has the ability to write code snippets in popular programming languages such as JavaScript, Python, C#, PHP and Java. Or generate sample CSV input for a data science problem. Or create bash scripts or infrastructure-as-code templates in JSON or YAML. And a lot more.
Let’s see an example. Maybe you need some boilerplate code for a simple index.html page that says “Hello World.” Using a natural language request, you can turn ChatGPT loose to solve this problem.
Not only does ChatGPT generate some (copy-pasteable) code, but it also explains what the code is doing, which can be especially helpful if you’re new to the language.
Need to style this webpage using some CSS? Let’s ask!
I know what you’re thinking: “I can use AI to write CSS? YESSS! If you tell me it can write regular expressions too, then I’m totally sold.” (Hint: it can!)
So. Just because you can write code with ChatGPT, does that mean you should? There are a variety of opinions on this. On one side, people argue that using an AI tool to write code makes you lazy and unable to think for yourself. On the other side, folks say that leveraging ChatGPT can make you a faster programmer, freeing up your time to focus on the more important things like architecture, best practices and business requirements.
I can see both sides of the argument. Let’s take a look at some pros and cons.
Let’s see what ChatGPT has to say about its own trustworthiness.
Even ChatGPT is aware of its own limitations! Just as you wouldn’t rely on your phone’s autocorrect functionality to send an important text message, you shouldn’t rely on ChatGPT for writing perfect code.
Take secure coding, for example. Remember that ChatGPT works by “learning” a huge set of existing data. In the case of ChatGPT version 3, it was trained on data through the end of 2021. Because the cybersecurity landscape is constantly changing, and new vulnerabilities appear every day, ChatGPT won’t have the latest intelligence to inform the code it writes.
ChatGPT has no knowledge of your specific requirements for authentication, secrets management, third-party components, vulnerability scanning and so on. It might give you boilerplate code with a placeholder for hard-coded credentials. If you don’t know that those should be stored in an environment variable or in a secrets management service, then this is a huge security risk for your application.
Ultimately, while ChatGPT is good for writing code snippets and simple applications, human developers have the critical job of putting the pieces together and applying best practices.
When you need to learn a new programming language or feature, what do you do today? You might search for tutorials, watch courses, try writing and running code to see what it does. This likely involves jumping around to several different resources, which can be time-consuming. And how many times do you encounter errors trying to run code you found online? For me, it’s almost always!
ChatGPT can reduce the amount of time it takes to do all of this. It effectively aggregates information from the many sources it was trained on, and presents them to you in a single interface. It also explains what the code does, and sometimes even gives you alternative ways of doing things. It’s like having a real-time tutor with you as you’re writing and reading the code.
Another huge bonus of learning through ChatGPT is the fact that it uses natural language processing for input and output. Meaning, just ask questions in plain English, as if you were asking a mentor or a friend. You don’t have to know exact technical terms or syntax to ask the question.
You can also refine and build out your conversation over time. If you didn’t quite “get” a concept that it explained, you can ask something like, “Can you explain that in a simpler way?” Or, “Can you explain that for a 5-year-old?” Being able to tailor responses to your current level of understanding is a pretty remarkable benefit.
So far, we’ve focused on using ChatGPT to write code, but there are several other ways it can make you faster at your job. For example, it can explain code for you, help you refactor, write test cases, and even fix bugs.
Let’s say you found some code on StackOverflow, but you don’t quite understand what it does. Let’s ask ChatGPT to help.
And voila! An explanation that can help us better understand the code.
How about getting some help refactoring and cleaning up our code?
And let’s see one more example of how to get help with unit testing. We’ll ask ChatGPT to generate unit tests for the Person class referenced above.
As you can see, there are tons of ways you can use ChatGPT to speed up everyday tasks. As always, you’ll want to validate the output it gives you, but as a starting point, this is pretty hard to beat.
As AI tools become more and more prevalent in our lives, the way to get an “edge” is to know how to use them effectively. For ChatGPT specifically, that means you’ll need to be able to write effective prompts to get the answers you want, and quickly. Here are some templates you can use.
Prompt template: Act as a [technical role]. Write [a description of the thing you want to write, using as much detail as you can.]
Example: Act as a front-end developer. Write code to validate a contact form that includes name, email address and message. The email address is required and should be in the format of a valid email. If the form is successfully submitted, display a success message.
Prompt template: Act as a [technical role]. The tech stack is [describe the different technologies you’re using]. Write [a description of the thing(s) you’re building].
Example: Act as a full-stack developer. The tech stack is AWS Lambda, DynamoDB, API Gateway and HTML. Write a Lambda function to calculate the sum of two numbers input by the user and save them to DynamoDB. Write an HTML file with input boxes for two numbers. When the user clicks submit, pass the two numbers to API Gateway.
Prompt template: I am getting the following error in my code [paste in the error]. How can I fix it?
Example: I am getting the following error in my code: Module not found: Error: Can't resolve './app'. How can I fix it?
Prompt template: Act as a [technical role]. Describe two different technologies to [accomplish some task]. Give me pros and cons, along with examples.
Example: Act as a data analyst. Describe two different technologies to do exploratory data analysis. Give me pros and cons, along with examples.
ChatGPT is very impressive, and it launched the “AI revolution” into overdrive, with new tools and features coming out every day. And because it’s continuously learning through user feedback and new data, it will continue to get better and better. Which begs the question: Will ChatGPT take my job?
As a programmer, remember that your ultimate job is to translate business requirements into code. That requires a lot of analysis, creativity, critical thinking, weighing different options, architecting, optimization and so on. Humans are much better at those skills than robots are, and I don’t think ChatGPT threatens that.
Also, as we’ve seen from the examples above, you need to understand how a technology works in order to ask the right questions and validate the answers that ChatGPT gives you. In other words, you need to be a skilled developer to effectively use ChatGPT for developer-related things. But let it do the tedious work that you likely have to search for anyway.
In short, I think ChatGPT will be used to accelerate work, just like IntelliSense, static code analysis, autocomplete, compile-time error checking, automated testing, IDEs and other developer tools have for years. It’s another tool in the toolkit to make you a better, faster programmer.
22 videos|29 docs|3 tests
|
1. Can ChatGPT write code? |
2. Should you code with ChatGPT? |
3. Is ChatGPT coding trustworthy? |
4. How does ChatGPT help to grow your coding skills? |
5. How else can I use ChatGPT as a developer? |
|
Explore Courses for Software Development exam
|