Should I pass by const reference or by value?

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


Related C++ videos

Links to stuff I use (helps support the channel):
Рекомендации по теме
Комментарии
Автор

Absolutely good idea. Divide the videos into multiple topics 🙏

youssefmohamedabbashabib
Автор

As a newbie programmer in C/C++, I use const references all the time, but I never truly understand when or why I should pass by const reference or by value. I learned a lot from today's video and am looking forward to seeing short films that focus on specific topics. Huge thanks!

RekiDragunova
Автор

A completely agree with you that passing primitive data types by reference is not a great idea. It will most likely prevent compiler optimizations. However, I think its probably a good idea to pass custom types by reference, even if they are small. The reason being that their size (and internal behavior) can easily change in the future, without the programmer later realizing that these function parameters all need updated to reference types. After 20 years of programming, one thing I've learned is to treat everything I've touched as unstable and dynamic.

robertmoats
Автор

This was definitely more easily digestible and focussed than 40 minutes of code review that goes in five different directions. I smashed like so hard on this that I almost dropped my phone.

seargd
Автор

I heartily approve of doing the code reviews by topic. If it tells you anything, this is the very first one of your code reviews I've ever watched--specifically because it wasn't ridiculously long, and I could see in the title that it was about something I might find useful.

You might get fewer views per individual video this way, but I have a feeling you'll get *way* more total views overall.

Lockdheart
Автор

That "it gots darker here" got me 😂

mateuszabramek
Автор

Divide by multiple topics, that will help your channel on the long term as more videos will popup on YouTube search. And that will help less skilled programmers(like me) to learn specific topics.

vitormoreno
Автор

this is absolutely a better format, not only because my attention span is garbage
but also it really helps to build a library of "advice" video that's easily searchable even without the context of the code review
this kind of advice is quite rare in a normal beginner tutorial and StackOverflow can be quite asinine about it
this way your video can reach a broader audience who just need specific advice

aronseptianto
Автор

9:43 yes! this is a fantastic idea. I only clicked on this because the title was interesting. I never click on code review videos

dXXPacmanXXb
Автор

I like the idea of splitting the code review video by topic! It taught me a lot. Hope to see you sharing more videos like this in the future.

stvreumi
Автор

This format is a good idea, and you could also add this video to the C++ series as it covers a pretty interesting topic that fits into it ! Cheers

Balouxe
Автор

100% love the shorter videos. Recently I haven't been able to find the time watch longer code review videos, so breaking them down makes it much easier

amayesingnathan
Автор

I just want to join all those that have said that it is an excellent idea to divide the code reviews into smaller videos focusing on one concept. It is super useful!!! Also, you get the opportunity to explain the same concept in multiple and different code sets which will greatly help understand better the concept, you know, by looking at it from different angles and use cases.

mln
Автор

Great Idea go for it. That is the exact reason why I watch long code review videos.

At any random time in a video, you give a specific knowledge for a specific situation that normal learning seriea doesn't even think about to teach us.

For example this video enlighten me about r and l-values. Thank you for that. Learned C++ with your C++ series years ago and now I can develop custom tools for the games I make with Unreal Engine.

PuraTvOyun
Автор

I really like the short, by topic code review!

fabiannedelcu
Автор

Just look at the assembly code my friend, I bet you will get a couple of surprises, particularly with private methods. Hint: the compiler does not always honour the argument passing convention you specified

RelayComputer
Автор

Making small videos for certain topics is very good idea. Never watch your code review videos before, but watched this video because of intresting topic. Often was asking myself the same question, and now I have an answer. Thanks a lot!

fyntyaka
Автор

As you said, a big video on this would be really cool. Thanks for all your work :)

harleensingh
Автор

I look forward to your bigger video on this :) I also enjoy this style of code review more, it's more descriptive to what the video goes over

kent
Автор

This video is good advice, it's basically F.16 in the cpp core guidelines: For “in” parameters, pass cheaply-copied types by value and others by reference to const. F.15 has a really good diagram that illustrates all the choices.
IMO it's a good idea to keep your argument definitions 'const', even when receiving value types. Especially in larger methods it's useful to know for certain that a given argument hasn't changed.
Also, don't use 'new', 'array'/'vector' would trivially give you the all-important move constructor for that buffer.

Spongman