ChatGPT can write better code than me

Check out my courses:
Become a Patreon and get source code access:

Hello everybody I’m Nick and in this video I will take a look at the brand new AI chatbot laucnhed by OpenAI called ChatGPT.

Don’t forget to comment, like and subscribe 🙂

Social Media:
Follow me on GitHub:
Follow me on Twitter:
Connect on LinkedIn:

Keep coding merch:

#csharp #dotnet #chatgpt

Hello everybody I’m Nick and in this Video I’m going to introduce you to the Brand new AI chatbots released by open AI called chat GPT it is an AI chatbot Trained to effectively have dialogue so It can keep context and keep answering Your questions knowing the previous Context and it has a cutoff point on its Knowledge in the end of 2021 so if Something after the end of 2021 has been Released its knowledge is very limited Now the interesting thing is that one of The suggestions on the examples over Here is how do I make an HTTP request in JavaScript so in this video I’m going to Put it to the test and see what it can Do for me as a c-sharp developer I’m Gonna get it to write some code try to Optimize some code and see how far it Can go and how much it understands maybe Get it to write some unit tests now this Is another blind reaction I actually had A two and a half hour playing around Yesterday on my live stream and you can Go and watch that as well if you want But from what I’ve seen I’m very Impressed and I can confidently say that This will give Google and stack Overflow A run for much money and from what I’ve Seen until now I believe it’s even Better than GitHub co-pilot but let’s See if you like to have content and you Want to see more make sure you subscribe Bring this notification Bell and for

More training check out And I’m going to start simple and say Write a c-sharp method that accepts a Good as a string and returns a base 64 Version of the good so let’s go ahead And ask it and the moment I say it it Starts writing the method so do base64 Good string good here and then it Returns the thing and this is clearly Valid C sharp you can take this and it Works now there’s one thing I actually Do not like and that is that it is using Guide.pause and guid.pause can throw if The input is invalid so I can say please Also handle invalid input so if the good Is not a valid input and it understands That yes if you don’t have a valid good Then I should use try pause and it knows That if the string is not a valid Guild Return an empty string and then I can Give it more context on how I wanted to Handle this thing so maybe throw or Return something else it’s up to me now There’s one thing I don’t like it uses These two byte array here and we’re Wasting memory allocations so I can ask It can you optimize this code to not Have keep allocations just go straight Away and not only go straight away it Says oh yeah I’m gonna use span of byte And I’m gonna stack allocate 16 bytes Over here to write the byte of the good And then convert it to base64. it’s so Good this is actually things you would

Do if you wanted to optimize it it’s Very very impressive now let’s take it a Step further I’m gonna say that please Give me a method that went this morning You return good morning when this Afternoon you return good afternoon and When it’s evening you return good Evening so write a c-sharp method that Returns good morning when it’s morning Good afternoon it’s afternoon good Evening when it’s evening immediately it Starts writing and it goes get greeting It gets the current hour getting daytime Now and it says if the hour is from 0 to 12 then good morning if it’s 12 to 16 Good afternoon else good evening very Very accurate it says this method is Using the daytime now property to get The current date and time and then Extracts the hour so it explains the Code but what I want to tell it now is I Wanted to write unit tests for this Method so please write unit test for This method immediately it goes ahead And it writes tests so test morning test Afternoon test evening create a new day Time and here’s where the insane thing Comes in it actually parameterized get Greeting because if you remember good Greeting didn’t have a parameter now Daytime is a parameter in the greeting Itself because we need to inject the Daytime as a dependency because Otherwise this would not be uni testable

So I can say can I see the new code or Get greeting and it’s gonna go ahead and Show you the new chains now that it Accepts daytime it is so good and let’s See how far it kind of goes so obviously Now it’s using any unit I don’t use any Unit so I wanted to use x unit as my Test Library I also wanted to use what I Consider to be my standard way of Writing a test name which is test method Underscore should do something Underscore when something happened and Then I’m using fluent assessions for my Accessions so let’s go ahead and write That can you use x unit for the test Instead also use fluent that’s so good Accessions for accessions and since I Prefer using the naming pattern method Name underscore when should do something Underscore when something happened then Use that pattern instead okay I added an Extra F in the end but it understood it Was a typo and it went ahead and it goes Ahead and it does it so it now changed The use x unit affluent accessions it Uses the fact correctly arrange actor Said correct parameter over here and it Says get greeting and the name is get Greeting the method name should return Good morning when it is good morning It’s so good I can’t actually believe This how it goes in depth and explains And it says oh I use the naming pattern Because basically you told me and yeah

I’m using fluent assessions correctly It’s so so impressive and it doesn’t Even end there so I could say for Example now use the theory feature of X Unit instead so match all three tests Into one that uses ethereum has inline Data to represent the daytime and the Items it knows it just knows and it Changes the text as well so should Return correct reading when given time Of day I can’t believe this okay let’s See how far we can go with this then so I’m gonna reset thread and I’m gonna say Create and core 6 API that Returns the weather or a given City Using the open weather map API for its Data let’s see what it can do it goes Okay straight away the There dotnet6 specifically that’s the Right location by the way then it gives You details on every step of the way you Inject the open weather map API client So it did that very efficiently to not Have the logic in here okay I want to See the the code that it would write for That thing so show me the code for I Open weather map API client and the Implementation which is open weather map API class let’s see what it does this is Super impressive so it explains that This is the interface explaining how I Can call this API so the contract and Then the implementation is here and it Is injecting the client which is the

Best practice in core most People do this wrong and this thing Could do it correctly this is insane Okay and then gets the okay show me the Full get weather data for CTA sync Implementation because it’s omitting it From what I assume so it’s going to go Ahead and actually write this let’s see What it does so so it’s going to use the Ace to feed client I’m so impressed it Knows it needs a key and it’s injecting The key from The Constructor write Comments to explain what it’s doing so The API URL is here this is all correct Code valid C sharp that you would write It this realizes using is it new terms Of the Json the serialized object yeah It is I wouldn’t want to use noodles After Json but it’s not wrong it’s just You can use system.text.json this is Nuts okay so we have that can I push it Even further let’s say add resilience by Adding only in the project use it to Implement retries and circuit breaker Let’s see what it does now sometimes it Takes longer because it’s so heavily Used by so many people around the world So it can take for a second to start Typing sometimes and I am also getting Rate limited so just know that it’s not The thing being slow it is just that so Many people use it that it is being slow Here you go and it goes ahead and adds To add the poly Library into the project

It just gives you all the instructions It tells you use the policy dot handling This is and it knows to Cache it so it’s Not created every single time I am oh my God I’m sure I can tell it to add Exponential back off and a Jitter and it Will all work I am so impressed with This thing Wow and we’ll just keep going what I Want to tell you to do after this and of Course I can say continue it will Continue writing the thing it’s so so so Interesting let’s see if I can get it to Write some performance tests now and the Library I prefer for performance tests Is k6 so I’m gonna ask you to write them With this so write performance tests or This API using k6 let’s see what it does Yeah of course it knows how to use k6 And how to create the test Javascript File I the ah this is so useful this can Be a game changer it’s also a bit weird Like not gonna lie but this is a Perfectly valid load test it tells you How to run it as well and how to have a Threshold if any of those dividers Exceed 200 milliseconds of performance Test will fail because it’s checking on Percentiles I oh my God does it know how To do staging to do something like Spike Test okay write a spike test for this API start with 100 users run up to 10 1000 users and ramp down to 100 users Use the stages feature in the options

Constant let’s see if it can do it oh my God if it actually does this because It’s one thing for me to tell it to do Something and another thing for it to Accurately yes wow continue continue you Want to see the full implementation Continue I am yeah it can do it of Course it can do it to run the test and It even tells you how to run it okay the Code block is a bit broken so it sort of Reversed it because of the continuing But it is in preview so don’t expect Wonders but this is nuts can it convert It to any bomber so convert those load Tests to our performance this is what I Call them performance test to n bomber With C sharp and bomber is library That can do performance testing so let’s See if it can do that with the exact Same criteria yeah of course it can Convert it why did I have any doubt Well I don’t want to push it any further You get the point this thing will do Effectively anything you ask it to now Will it always use best practices from What they’ve seen no but it’s Significantly better in my experience Than co-pilot was when it came out and Even still in some cases so I would keep A very close eye on this and I will be Using it more and more but what do you Think do you think that now more than Ever are job security is in danger leave A comment down below and let me know

Well that’s all I had for you for this Video thank you very much for watching Press and fix my patreons for making Videos possible if you want to support Most probably gonna find the link in Description down below leave a like if You like this video subscribe more Because I like this ring the bell as Well and I’ll see you in the next video Keep coding

You May Also Like

About the Author: admin

Leave a Reply

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