C++ Weekly - Ep 371 - Best Practices for Using AI Code Generators (ChatGPT and GitHub Copilot)

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
Upcoming Workshop: Applied constexpr: The Power of Compile-Time Resources, C++ Under The Sea, October 10, 2024

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

yes! "Smart rubber duck" is the most perfect analogy I've seen thus far!

yephick
Автор

I think ChatGPT can be very valuable as a programming sparring partner, when your colleagues are not immediately available. Not necessarily to generate code, but to get some instant feedback about your approach. Of course, you do need to take the input with a grain of salt (rule #1), but as with the rubber duck, it is a very good way to get new input and possibly new approaches to solving your problems.

nikolajfogh
Автор

I'm a fairly low grade C++ coder, far from a guru and out of touch with modern best practice. I've just started using GPT4 via ChatGPTPlus to help me get some work done. First thing I did was get it to tell me how to do a simple project using Crytpo++ to encryt and decrypt some files. I didn't have a clue how to use the library and it probably would have taken me a week at least to research and get something working, but GPT4 wrote most the code and I had what I wanted within 2 days. Next I needed to load some .obj 3D models into the Unity game engine. This is C# and also I don't know much about using Unity. Again, GPT4 wrote most the code, as well as telling me how to make Unity materials and stuff, and I had it working within a day. The general cycle seems to be I ask it for code, it gives me some but there are a few errors, I tell it the errors and it tells me how to fix it, rinse and repeat. Sometimes I have to tell it the answer is too complicated or I want it solved a different way. And sometimes I spot glaring problems or it starts to go off on a tangent where the corrections to the code keep getting more complicated and over engineered. But mostly it's been pretty impressive.

MrHuman
Автор

Re point #4: ChatGPT mimics average PHP code found on the web by including glaring SQL injection vulnerabilities.

vytah
Автор

One thing I love to use chatGPT for is naming things or debating which function names are more intuitive.

oj
Автор

I would just add another point using Copilot: It can write some code boilerplates for you.
Let say for example I have to fill some struct field or have to manage Result and Option in Rust. Copilot is aware of your code and helps you in a very good way.

iamgly
Автор

That first rule is extremely important! Assume it's always wrong, very good advice I think

LogicEu
Автор

Thanks for very accurate description of AI without hype or unbased criticisms.

von_nobody
Автор

To understand how an LSTM cell (LSTM stands for Long Short Term Memory Network) works, I set myself the goal of implementing a forward and backward pass algorithm in C++.
I turned to ChatGPT for a code example. And if everything was ok with the forward pass algorithm, then in the reverse pass algorithm (backpropagation algorithm) there were so many of them that I had to study the algorithm myself and completely rewrite it.
But the most interesting thing was at the end, which I immediately did not pay attention to. The activation functions were written correctly, but their derivatives were not.
It is concluded that information that is often found in the public domain is reproduced correctly, the rest of the information is abstracted.

Alexander-qrnk
Автор

I asked ChatGPT to implement a type erasure class with SBO and it implemented... a templated class. The funny thing is: it did try to erase the exposed type. It also didn't bother to check whether the type fits into the buffer.

stanbarvinsky
Автор

A little rant about C++ and especially C libs. I wanted to generate a video, and the documentation for that library starts with how you can provide custom allocators, and how you can configure the library. And I won't read through the h.264 standard to understand your terminology. I believe that's why Python is easier to use. It has nothing to do with being dynamically typed or the number of keywords. That's why I use chat GPT all the time.

nonae
Автор

I asked ChatGPT to rewrite a simple Little Endian-dependent function of mine to be Endian-agnostic. It rewrote it to be Big Endian-dependent and (falsely) told me it was now platform independent.

I pointed out its mistake. It rewrote it back to the original function I gave it (😒) and, once again, told me it was platform independent. We went back and forth through that cycle a few times. It wouldn't give me a correct answer... it just kept finding a different syntax to give me the same wrong answer.

Best practice is to assume ChatGPT has no actual understanding of your question and its answer.

matthewmurrian
Автор

Great video, GPT-4 is a bit slow, but it's accuracy far exceeds GPT-3.5 imo. They still aren't good enough to make longer programs like interpreters or 2D games on their own though.

torarinvik
Автор

This is a good video and literally how I'm approaching this new toolset of ML models helping achieving.

I think the first thing to talk about that it's not just "AI" - this masks the whole algorithm and way of solving problems.
People think it is way smarter than what it is, therefore the first thing to do is to call it "ML model(s)" rather than "AI".

Understanding how a tool solves a problem will help you to use it properly, wielding Chat-GPT like it's another programmer is all kind of wrong.

TNothingFree
Автор

The new Amazon AI code generator cites its sources and the licenses

ziadabouwasaa
Автор

Arriving extremely late to this video, still want to say thanks!

seventyfive
Автор

My colleague describes the chatGPT code generation as pair programming all the time~

wizardy
Автор

That’s how I explained chatGPT to a friend, a smart rubber duck

brickspace
Автор

I find that ChatGPT jumps into writing code earlier than I would like, when I describe a problem I'm trying to solve I'd like it to stay closer to pseudo-code and debate the algorithm itself before it jumps into spewing garbage code and we get confused with syntactical rabbit holes or hallucinating nonexistent libraries.
I actually told ChatGPT NOT to write any code at all for some of my rubber duck sessions and it will still write the code, which can be frustrating.

NateHK
Автор

I just found another absurdity with ChatGPT...

It tried to implement a type trait that would verify, at compile-time, whether operator[] is defined for a particular type. That's reasonable and sane.

But what it thought it could do was verify whether operator[] was defined for specific argument _values_ and not others. You read that right.

It believed that value[0], value[1], value[2] could all be defined operations... but maybe value[3] is not _defined_. As in, throwing an out-of-range exception at run-time means the function isn't "defined" at compile-time. If that didn't make any sense to you, you're right!

matthewmurrian