Using AI to help me with C++

preview_player
Показать описание


💰 Links to stuff I use:

This video is sponsored by #Grammarly.
Рекомендации по теме
Комментарии
Автор

The DynamicArray class actually has a bug in it. It initialized capacity with 0 so it means the array can't grow because m_capacity * 1.5 = 0. GPT-4 is so much better at writing code than the free version

Rudy_YT
Автор

I'm glad I'm not the only crazy person who is saying "please" and "can you" to ChatGPT like it cares. Gotta keep that karma high when it turns into skynet so it doesn't kill you first lol

capsey_
Автор

I like the bug with the DynamicArray, default size of 0 means that it can never expand. So it will write out of bounds on a push_back. ( 0 * 1.5 = 0)

Keltheran
Автор

I've been teaching myself C++/SDL2 coming from a Python/Go background. ChatGPT has been invaluable so far as just being a thing I can ask questions about C++. I don't even ask it to generate code for me, I just ask questions about language features I'm curious about. It even remembers what we were talking about if I have followup questions an hour later.

TheKorath
Автор

It does a reasonably good job at explaining rendering pipelines and graphics APIs including majority of their features. I've been learning DX11 for about 9 months now and as soon as ChatGPT went live, my productivity sky rocketed because I can ask ChatGPT why I can't bind multiple textures to a single slot, or I can ask it how to use class linkages for creating more dynamic shaders. It's truly amazing.

christianwaldmann
Автор

Writing simple well researched and documented things like data structures is an easy task for ChatGPT because there's a ton of tutorials and examples for it. The first thing I asked it to write was a Red-black tree and the code was almost identical to the tutorial I found online in a couple of seconds. A lot bigger challenge for it would be writing complex code because due to the nature of a language model ChatGPT is basically guessing which is crucial to consider when it comes to language-to-language translation (like English to C++) because if the topic is not well represented in its dataset it would definitely make mistakes and\or need a lot of guidance to get exactly what you want from it.

Einygmar
Автор

I literlally started doing this a week ago with chat GPT to create a text based game with python just to see how it handles things. And my conclusion so far from my experience after spending around 20 hours on it :
- if you don't know how programming works, you will end up with a buggy code and it will be dysfunctional.
- if you are a beginner, this will help you learn how to do things in a really good way, as long as you make sure you make few attempts on your own before getting the code from chat GPT or by using the provided code for multiple things.
- if you are intermediate : this will be amazing for you. It will be basically allowing you to write exactly the code you want but much faster and bigger quantity than you could have on your own. And it will make sure that you you have less bugs (but not bug free, you still have to check what it wrote)
- if you are advanced with programming : this might be a bit frustrating for you, because it will be going at lower level than you expect and it would require multiple attempts. It struggles a bit with super complex ideas.

But the most important thing I discovered is that there is a hidden skill that I have absolutely no doubt will be taught in schools in the future : how to talk to AI and how to explain your idea/intention. I realized that the biggest struggle I faced with the AI is how to explain what I want to the AI. This skill certainly advanced a lot as I kept using it. But they should definitely release a course on how to communicate with it. Think of this skill like a googling skill. As you use google more and more, you learn to write the key words in a different order and you change certain words to make sure you get the wanted result or by using the + and - and other symbols.

The conclusion in this case is that your experience will depend on :
- your level with the specific language used (basic to beginner is already enough, but better makes it better)
- Your level of programming and problem solving : it helps understand the type of solution provided and the instructions to give
- your level at communicating your instructions or idea to the AI.( the AI can take an idea and turn it into code but can also take a solution and turn it into code)

samygafsi
Автор

You should really try out GPT4! The difference to GPT 3.5 is massive when it comes to coding.
For example I have written a Graph class in C++, with some functions to change the mode of travel, Dijkstra etc.
I've learned so much about C++ from GPT. As you just demonstrated, you can literally let it explain everything and argue with it

MrComefun
Автор

I'm sure somebody pointed it out by now, but the end bit happened because it ran out of context space. Happens quite frequently with chatGPT (although if you use GPT4 it's less frequent). One common way around this is to frequently re-prompt it with the code you're discussing. GPT4 generally generates much better code as well.

chrismanning
Автор

I have actually been using ChaptGPT for the past two weeks and it’s pretty impressive. The idea is that you tell it: “how would you refactor this js function” and it would give you suggestions and the refactored code. Then you can chat with it and tell it that: could you make it more functional by removing the for loop?… Then it makes that for you. I have “chatted” with it quite often during development and it’s seriously becoming an indispensable assistant. I don’t need to waste time going on google to find stuff when it can answer me there.

danielsimionescu
Автор

What is really interessting is that ypu noticed this phenomenon of improved answers by the model by simply giving it more context in your promts. There are actually research papers describing this. Si the quality of the output also depends on the quality of the input. You could also ask it to write bad code (can also be a fun experience ^^)

backfischritter
Автор

When I was in uni, doubling the size of the array when needing more capacity was used as an example to show how the amortised cost of resizeing could be O(1) even when the cost of doubling the array is O(n). The maths works out neatly when you double compared to multiplying by 1.5. So even if doubling is not commonly used in the real world, it is probably used a lot in text books etc.

morlankey
Автор

This OpenAI chat is absolutely amazing like a virtual professor giving answers to SF, FW or HW questions that can be modified while chatting with the AI. Thank you for sharing this beautiful tool

icemarek
Автор

14:50 When studying Data Structures in University I learned that when creating a dynamic array, if you double the capacity whenever the array is full you get O(1) amortized complexity for the push_back method. We also talk about tripling the capacity and seeing that it gives the same amortized complexity but that takes more memory so we stick with doubling the capacity.
We've never analyzed the complexity of increasing the capacity by 50% and all courses I've taken so far (when talking about a dynamic array) used the doubling method.
So I'm assuming that's why ChatGPT said it's more common.

Just wanted to note that, great video as always Cherno!

NubPaws
Автор

As others have mentioned, GPT-4 (paid version) is much more impressive than the free GPT-3. Even that though still has limitations. I've found it extremely good at solving sort of "standard" problems like resizeable arrays or even more complex problems that use libraries, but if you start going into really complex requirements that are somewhat novel and specific to your application, it can really start to struggle.

namr
Автор

Multiplying the capacity by a factor greater than one wins over a fixed size increment, which is asking for fragmentation. (Found by sad experience.) I don't know whether anyone's experimented and found that 2 is better than say 1.5.

JamesJones-ztyx
Автор

You're heavily anthropomorphising CGPT. It's a text completion algorithm, and it will change its output depending on context.
In its training data, programs written with "using namespace std" likely had generally more simple styling and "bad practices". When it moved out of that context, many things changed, like the naming convention for private members, and naming the class "dynamic" instead of "resizable".

It does not understand what it's doing, it's simply predicting the next word in a sequence. It is incredibly powerful in that, but when the most likely completion for a chain of symbols is something wrong, it will still write it.

-Kirby-
Автор

I would like to see more videos with you digging into A.I. and C++ programming. Its very interresting stuff

olepetterhagen
Автор

GPT-4 has become an integral part of my workday when programming. I am working with C++ and OpenGL, and if I get stuck with something I always ask GPT first, before going to stack overflow.
I see you are using GPT-3 though. The difference is huge! Try GPT-4.

mariusirgens
Автор

You can ask for the same prompt x times, and it will generate a completely new response each time, hence why it gives you different naming etc. Also, it's not that it actually understands the code, it's a language model, it's good at mimicking how someone who actually understands the code would write. That's also why it can often give you flat out wrong code or answers and be completely "sure" it's correct. I find these tools to be good for boilerplate or to help me debug if I am really stuck. It's nice to just feed it an entire file and ask "point out any potential problems" with this code. But it's not to a level where you can rely on it for any actual work yet.

apresthus