Meet the AI That Understands Code – OpenAI ChatGPT

Unlock the power of AI for your software development – OpenAI ChatGPT can give you instant feedback on code, write tests autonomously and even provide helpful software design tips. In this video, I share how to use it to improve your workflow today. I also share some thoughts about how it might affect the future of software development.

Link to ChatGPT:

👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework:


🎓 Sign up to Brilliant now and get 20% off the annual subscription:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

💬 Discord:

🎥 Video edited by Mark Bacskai:

🔖 Chapters:
0:00 Intro
1:08 What is ChatGPT
1:25 ChatGPT explains unclear pieces of code
2:27 Asking ChatGPT if the code contains bugs
3:09 ChatGPT writes tests for code
4:38 ChatGPT gives design improvement tips
6:12 ChatGPT gives tips for increasing cohesion of the code
7:49 What to expect in the future

#arjancodes #softwaredesign #python

DISCLAIMER – The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

About a week ago openai released Chad’s GPT which is a system you can chat with Now normally I have my video schedule a Few weeks ahead of time but I think we Need to talk about this too because chat GPT actually understands code and I Think it shows us a glimpse of what the Future of software development is going To look like what I’ll do in this video Is show you what it does how you can use It to improve your coding workflow and Also share some thoughts about the kinds Of things we might expect in the future The old-fashioned way of writing code is To actually develop your own code Analysis skills and that’s useful for Improving your own code but also Analyzing code that’s written by others I have a free workshop on code diagnosis That’s going to help you that’s Available at Diagnosis and contains a three Factor Framework to help you do code reviews More effectively and more efficiently And uses production code Existing libraries that you might Actually use yourself to show how it Works so iron.coles slash diagnosis to Enroll for free and I’ve also put the Link in description of this video now Let’s dive into chat GPT chat GPT is Currently free this is what the Interface looks like you can basically Type questions here and it’s going to

Respond to you but what’s cool is that You can also submit code to it and then Ask questions about that code and that Potentially is helpful to your workflow Today I’m just going to try a few things And see whether that works so the first Thing where this might be useful is if You have some piece of code that you Don’t fully understand perhaps one of Your colleagues written it or you wrote It a couple of months ago and you’re Trying to understand what it is doing Exactly here I have an example of piece Of code from one of my earlier examples Called loon checksum and this verifies That a card number actually adheres to The loom checks on so we can copy this Code and then I’m going back to my chat Interface and then I write explain what Function does And now I’m simply going to paste the Coding and let me send that and see what It comes up with so the explanation to Me looks pretty good it detects that This is the loom checksum algorithm and Then it actually explains what that is And it actually notices that this is Specifically used for credit card Numbers which is pretty cool and then it Also says something about the structure Of the function itself so it says that Well it has a digits of function that Gets the digits and a card number and Then it calculates the Jackson as

Follows now what I’m going to do is I’m Going to ask whether this function loon Checksum that I’ve used before contains Any bugs and I’ve intentionally changed The checks on value here from 0 to 1 and See if it figures out that this is Actually wrong okay so it didn’t find That bug but it did find suggestions to Improve the code so it simplifies the Function by using the map function to Compute the sum of the organism even Digits and then you can remove the Digits of function since it’s only used In this function itself and what it also Changes that card number should now be a List of integers apparently it doesn’t Know about list locally’s list that you Can also use this as a type hint but That doesn’t matter that’s an easy thing To fix what you can also do is ask the Program to write some tests for you [Applause] So now I’m going to ask it to write unit Test for the loom checksum function so This is what it comes up with it created Test loon checks on class it then added Three methods testing a valid number Testing an invalid number and testing a Single digit card number and here it’s Of course that needs to be false this Needs to be false and this needs to Result in true and the interface also Allows to copy the code so what I did is I just took the code that the AI

Generated that’s the Loon checksum Function right here and the class to Test it and now I can actually run this Test and see what happens and we can see That it ran these tests and all of the Tests pass okay so just as a sanity Check I’ve replaced the Loon Jackson Function by my original version and I’ve Changed the test to actually have Strings now instead of list of integers And now when I run the test again we see That these tests are actually still Valid so it seems it actually created The right unit test for my system and it Even covered the most important cases Which is valid number and involved card Number and a wrong single digit card Number so this can actually be pretty Useful if you’re writing simple Functions and you just want to have some Tests and make sure that you cover all The edge cases you’ve seen that the chat Agent also actively gives you advice on Changing the code and making the code Better but you can actually also ask it Directly for example here I have an Employee class that’s from one of my Earlier examples about code smells and I’ve just pasted the code in here and I’m going to add a question How can I improve The design Of this code and then I submit this and Let’s see what it comes up with so let’s

Scroll up it says you can use typing Mode to specify the types of the payout Parameter and the return value of take Holiday methods so actually this is Already what I’m sort of doing so that’s Not really correct it just tries to Change that a bit and then use string Formatting instead of concatenating the Strings so when we look at the example This uses F strings which I think is Actually better than using a classic String formatting but they also see that It depends very much on the code that The model is trained on and then another Thing you can use the logging module Instead of printing messages now this is Useful because currently of course this Is only printing out stuff but using the Logging module is way better and then Let’s see you can move fixed vacations Bail to separate model and imported this Will make the code easy to read and Maintain then it says here’s an example Of the code could be modified to Incorporate these suggestions so this One is still here but it did add a Logger and then it create the employee Class it changed the type of payout to An optional type which I guess makes uh Makes sort of sense so it gives it gives It a default value I don’t think we have That in the earlier version or we didn’t And then it applied the more classic Python formatting which is not really

What we want do you have any tips For increasing cohesion of the take a Holiday methods let’s see what it Responds to this so I think this is Pretty cool explains what cohesion is Which is useful and then it actually Recognizes that we should split the Method of into two separate methods one For taking a holiday and one for paying Out a holiday you can see in this Version we have on big if else statement If payout so that’s a flag you should Generally avoid that in methods then It’s going to do this otherwise it’s Going to do this it gives some other Tips as well like use meaningful Descriptive method variable names make It easy to understand the code avoid Using Global constants inside the Methods instead pass the necessary Values as parameters avoid catching and Silently ignoring exceptions in the Methods so that’s also what you see we Were doing here like try accept Exception of course this you should Never do in Python and actually detects That so that’s pretty cool and here it Suggests the updated code so we have the Two methods now instead of one single Methods it has removed move the Exception it did introduce again the Python classic formatting but obviously Models like this are going to get better Over time and they’re going to also make

Better suggestions I already think it’s Pretty amazing that it makes this kind Of suggestion so these are already some Examples of how you can use this tool to Improve your workflow you can let it Explain pieces of code to you that are Not clear you can use the tool to help You find bugs you can ask it about the Design of your code and suggest Improvements and you can also ask it to Write tests for your code so what does The future look like does this mean that Basically as developers were out of a Job and what does it mean for me as a Content creator does it mean that I can Just stop making videos because well the AI knows everything so you don’t need to Learn anything anymore about software Design or maybe I could make other Content like I don’t know just making Jokes about Dutch people or something Although Foreign So what does this kind of tool say about The future well of course we already Have some of these tools that integrate In some way with our IDE tools like tab 9 GitHub copilot which I’m still using By the way and these already show some Of the basic possibilities of how these Systems can help you write code more Easily by for example doing automatic Code completion now I did a video about GitHub co-pilot already a while ago if

You want to watch that I’ve put Link at The top now of course these models They’re going to become better over the Years an earlier model from openai Codecs also gives suggestions that can Explain code but I feel chat GPT does a Much better job at giving specific Suggestions so there’s already within One year pretty big Improvement and We’re going to see more of these Improvements over the coming years so That’s really exciting now chat Interface is not the ideal interface for Software development of course we’d like These tools to be important naturally Integrated into our IDE so I’m quite Order this is going to happen over the Coming years think of ide’s naturally Suggesting improvements to your code While you’re typing it for example you Might get some kind of alert that hey Did you cover this Edge case in your Function and if not would you like me to Add the code for that or how about you Click this button and then I’m going to Generate all the unit tests for you and Testing code you can even take that a Couple of steps further I mean Hypothesis testing library is already Taking steps in that direction where It’s going to automatically generate Tests for you based on edge cases that It learns and I think AI systems are Going to be really helpful for that

Perhaps in a few years tools like GitHub Bit buckets Etc are going to have Basically all day running AI systems That check your code for all sorts of Bugs and that report these blocks to you Including suggestions of how to fix them I don’t believe this is going to Completely replace developers at least Not for a coming 5 to 10 years years it Will probably become a better and better Coding assistant that just takes off Some of the work and we already see that In other domains there’s for example Also that you can use for Writing content and that’s just a Helpful tool that helps you edit your Content and similarly this kind of tool Is going to be helpful for you to write Code faster in longer term these types Of tools are going to change your role As a programmer you’re going to focus Less on let’s say low level coding but Maybe become more of an architect and That the system actually handle the Complex cases for you and that also Brings us closer to people who don’t Particularly have a coding background to Still be able to come up quickly with Applications or prototypes so they can Test whether it’s something that they Want to develop further this might also Change the way that programming Languages work at the moment a Programming language is basically a set

Of syntactical constructs higher level Constructs that are translated by an Interpreter or compiler into lower Levels machine code the whole goal of The programming language is to make sure That we as developers don’t have to type Low level machine code but for an AI System this is all irrelevant an AI System can simply learn the model and Then generate new outputs this could Mean that programming languages Themselves might actually start relying On AI for example you could have certain Syntax extensions that under the hood Don’t directly generate machine code but Actually use AI to generate that code And then the program language is going To get even closer to the way that we Think the way that we communicate and I’m really curious to see where this is Going and how this is going to change Software development how this is going To change programming language and the Way that we design and write code I hope You enjoyed this closer look at chat GPT It’s available for free I’ve put the Link in description so check it out now It’s perhaps still a bit too early to Have ai take over your code writing Tasks and there are still a couple of Simple things you can do to improve your Code and the video about that recently You can check it out here Thanks for watching take care

See you next week

You May Also Like

About the Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *