Meet the AI That Understands Code – OpenAI ChatGPT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
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 ion.com 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 jasper.ai 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
Info
Channel: ArjanCodes
Views: 47,252
Rating: undefined out of 5
Keywords: openai, chatgpt, ai, AI coding, software development ai, Artificial Intelligence, chatgpt explained, chatgpt coding, chatgpt examples, chatgpt programming, chatgpt demo, chatgpt python, chatgpt3, chatgpt tutorial, chatgpt API, chatgpt conversation, openai chatbot, openai chatbot gpt, openai gpt 3, openai codex, openai playground, openai whisper, openai tutorial, open ai, gpt 3 chatbot, chatgpt openai, gpt 3, natural language processing, openai chatgpt, how chatgpt works
Id: 6NWhYgMK9Hc
Channel Id: undefined
Length: 12min 29sec (749 seconds)
Published: Fri Dec 09 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.