3 Simple Ways ChatGPT Can Make You a Better Coder
Aug 15, 2023
3 Simple Ways ChatGPT Can Make You a Better Coder
In this video I show three ways you can use chatGPT to improve your code. Follow me on twitch for live coding streams: https://www.twitch.tv/medallionstallion _ My other videos: Speed Up Your Pandas Code: • Make Your Pandas Code Lightning Fast Speed up Pandas Code: • Make Your Pandas Code Lightning Fast Intro to Pandas video: • A Gentle Introduction to Pandas Data … Exploratory Data Analysis Video: • Exploratory Data Analysis with Pandas… Working with Audio data in Python: • Audio Data Processing in Python Efficient Pandas Dataframes: • Speed Up Your Pandas Dataframes * Youtube: https://youtube.com/@robmulla?sub_con … * Discord: https://discord.gg/HZszek7DQc * Twitch: https://www.twitch.tv/medallionstallion _ * Twitter: https://twitter.com/Rob_Mulla * Kaggle: https://www.kaggle.com/robikscube #chatgpt #python #coding
Content
0.24 -> ChatGPT! I'm sure you've heard of it by now.
It can do a lot of awesome things such as
5.46 -> answering questions, writing book reports, writing
awesome poems, and of course, it can code. So,
12.96 -> I know a lot of people are scared that chat GPT is
going to take over coding completely and we're all
18.42 -> gonna lose our jobs. This is horrible. I'm here
to say, calm down, it's not that bad. In fact,
24.84 -> there are many ways chat GPT can help us become
better coders. That's why, in this video, I'm
31.86 -> going to show you three ways that you can use chat
GPT right now to make yourself a better coder.
39.18 -> Number one: adding comments to code. So, here I
have an example function where I'm given a file
44.34 -> name, I open that file, and I print out each line
in that file until the end. Let's go over here to
49.68 -> chatGPT and tell it: can you add comments to
this python code to make it more readable?
61.2 -> Let's put things in triple quotes so it's
easier to know that this is a code block.
65.1 -> And it's done giving the solution, let's copy
this over into my notebook. And you can see it's
70.74 -> added comments to each line. There's a little
bit of over-commenting, and of course, it's up
76.32 -> to you to double check the comments to make sure
they're right, but it can save you some time.
80.7 -> Now, another way that this could also be
helpful is if you have a bunch of code that
85.08 -> you don't understand how it works. You can
ask chat GPT to write the comments for you,
90.54 -> and then it'll give you a better idea,
potentially, of how the code works.
94.98 -> Number two: using chat GPT to make your
code easier to read. This is just a fake,
100.26 -> complex function that has a lot of bad practices.
We see that we're checking A and B separately,
105.9 -> and then we're also using this if return
and then if not return back to back. Let's
111.96 -> give this to chat GPT and see if it can
make it more pythonic and easier to read.
117.9 -> Here's the amazing thing about this: not
only did chat GPT give us a more pythonic,
123.6 -> easier-to-read function, but it also listed
out all the changes it made and explained
129.12 -> why that makes it more pythonic and easier
to read, all the way down to removing this
133.74 -> one blank line in the code. Of course,
you need to know how your code works,
138.54 -> so don't just rely on chat GPT to
do it for you, but in this example,
143.52 -> it's clear that chat GPT was able to take this
simple function and make it more pythonic.
149.82 -> The third thing I want to show you that chat
GPT can help you with is writing unit tests.
154.38 -> This is something that many coders just avoid
doing altogether, but it's very good practice
159.78 -> to write unit tests for your code. So, we
have an example class here called Rectangle,
165.72 -> where we give it a height and width, and the
get_area method should multiply the height and
171.36 -> width. We also have some setters here. So, let's
give this to chat GPT and see how well it does.
179.52 -> And there we go! It's provided us a unit test for
this and also is explaining that the unit test
189.18 -> covers these three methods for the Rectangle
class: get_area, set_width, and set_height.
194.94 -> So, there you have three examples of how you
can use chat GPT to make your coding better.
Source: https://www.youtube.com/watch?v=NcCNw_UXnOc