Passing function parameters correctly in C++ :: Tutorial on different references

  Рет қаралды 30,296

Bisqwit

Bisqwit

Күн бұрын

Пікірлер: 214
@w1d382
@w1d382 4 жыл бұрын
The chart in the video: bisqwit.iki.fi/jkp/params-flowchart.png Putting it in the comments as suggested in Discord.
@nBoxes
@nBoxes 5 жыл бұрын
Thanks, please do more of these c++ tutorials.
@kelvinvalencio2
@kelvinvalencio2 5 жыл бұрын
Jesss plis
@Bisqwit
@Bisqwit 5 жыл бұрын
The editor used in this video is Joe, joe-editor.sourceforge.io/ . It is available in the package managers of nearly all Linux distributions. Here it was run in That Terminal, the subject of the livestream series I did earlier this year: kzbin.info/www/bejne/b5aWaYKIp9CVqsU This terminal is what adds the person animation in the title bar. Previously this feature used to be built into That Editor, github.com/bisqwit/that_editor , which I used in my videos for years.
@cortex5749
@cortex5749 5 жыл бұрын
U liar :(
@0day694
@0day694 5 жыл бұрын
Thank you Bisquit! Your videos always have extremely high quality. Please, make more practical videos about C++, similar to your compiler series.
@liorcraftblockil5995
@liorcraftblockil5995 5 жыл бұрын
אתה באמת ממש ממש טוב במה שאתה עושה, תמשיך כך!
@Bisqwit
@Bisqwit 5 жыл бұрын
Thank you!
@vector4606
@vector4606 5 жыл бұрын
I've always been told not to use pointers, and i always understood that and avoided them but always ended up needing them, especially for functions which needed to test if a base type was a certain derived type. But after watching this awesomely brief video I understand how to get that functionality without brutal pointers.
@Rohrschacht
@Rohrschacht 5 жыл бұрын
This is a very understandable and concise explanation. I think I understood the examples and liked the video very much, thank you for sharing :)
@icecofffeee
@icecofffeee 5 жыл бұрын
Great video, i love how its more than just showing the different ways to make functions, but dives deeper into why you should use the different methods. The flow chart is amazing!
@Bisqwit
@Bisqwit 5 жыл бұрын
I have subtly censured MSVC on a number of occasions in my videos. Microsoft is not exactly reputed for making standards-compliant products. Thank you, @+alex0flex , for proving again why my criticism is justified. Spot the odd one out: godbolt.org/z/pofGJD (In reference to the claim I make in the video at 3:07.) Note: If you add the /Wall compiler option, MSVC at least gives you the warning: “warning C4239: nonstandard extension used: A non-const reference may only be bound to an lvalue”. Another good reason to always compile with warnings on.
@johnoneil9150
@johnoneil9150 5 жыл бұрын
I've spent hours reading pages looking for a recommended best practice for using rvalue references, and this is by far the best explanation I've come across. Thanks again bisquit.
@loklobo
@loklobo 5 жыл бұрын
to be totally sincere, english isn't even my first language and i don't understand almost nothing about programing. but there's something about the way you explain the matters that is really catchy.
@JoLiKMC
@JoLiKMC 5 жыл бұрын
I gotta agree with some of the other comments: these skits are absolutely awesome. Not being a programmer of _any_ sort, myself, the skits really clarify the meaning of what was said in a way that is both amusing and doesn't make me feel like I'm being talked down to. Thank you, Joel! And, thank _you,_ Runtime Visualization Players™! (No, he didn't bribe me to say this. I just _happen_ to sound like a planted commenter.)
@djpeterson7479
@djpeterson7479 5 жыл бұрын
C++ is one of those languages that looks super ultra complicated until you understand the reasoning behind everything. Then it's like "oh yeah! That makes sense!" Dare I say I like C++'s overall design better than Java or C#. I could do without the header files, though, but I understand why we still need them. Here's to modules being awesome so we can start to migrate away from headers. Great video, Biz!
@TheBackyardChemist
@TheBackyardChemist 5 жыл бұрын
I think pointers still have an use in C+, I use them for optional output arrays. So the default value of the pointer is nullptr, and I can check inside the function if the ptr is still nullptr. If it isn't then the function generates additional data for the caller, and stores it at the ptr given by the caller.
@Bisqwit
@Bisqwit 5 жыл бұрын
In your optional output arrays example, how do you deal with the size limit? I.e. telling the called function how much room there is for writing.
@TheBackyardChemist
@TheBackyardChemist 5 жыл бұрын
@@Bisqwit I do not have to, I actually pass a pointer to an std::vector, instead of a plain array.
@Bisqwit
@Bisqwit 5 жыл бұрын
Oh I see. You can do that without pointers too, though. godbolt.org/z/1O7mKg
@programadormirim6616
@programadormirim6616 5 жыл бұрын
I am Brazilian and I do not understand English at all. But your intelligence, mixed with your voice make me spend hours and hours watching your videos!
@Bisqwit
@Bisqwit 5 жыл бұрын
Subtitles are available!
@SaarN1337
@SaarN1337 5 жыл бұрын
Pleases me to see how big your channel has become, almost 100k who appreciate your dedication and are hungry for knowledge. I really can't get enough of you vids, Joel, thank you so much.
@themcc1879
@themcc1879 5 жыл бұрын
I love videos about c++. You explain things very well. Considering I don't use the language professionally I like learning about it. I also enjoy the TAS demo scene-esque videos. Seeing code auto inputted then the result being shown is entertaining.
@xi7647
@xi7647 5 жыл бұрын
Great example and explaination of rvalues use! Finally a very clear and straight forward explaination, I struggled to explain this before to other people.
@afsarabenazir8558
@afsarabenazir8558 5 жыл бұрын
You are so brilliant! Also love your accent! Please continue doing more cpp tutorials. The phonebook example clips were hilarious.
@TheVoidOne4868
@TheVoidOne4868 5 жыл бұрын
Congratulations on your new subscriber milestone! I have been a fan of your channel for at least 4 years and the content that got me into it was none other than tour livestreams. Back then you did not have many livestream videos but those you had I have watched them at least 3 times each(especially the one with the mega man hack). To me, it is extremely interesting to watch other people code, because you get to see both their thought process as well as interact with them. If you decide to do more livestreams I would suggest you first make a QnA video in which you address the most asked questions and then during the livestream just point your viewers to it. I enjoy all the technology related stuff that you make so just keep up the good work man. I really enjoyed this video too, it is a very confusing topic to many c++ programmers but you nailed the explanation as always . Last but not least some more hardware related videos or even embedded systems projects with an arduino would be realy nice to see. Have a nice day Bisqwit!
@JonBlanton
@JonBlanton 5 жыл бұрын
Great video, you did an excellent job breaking down and explaining this topic! The only part that I found a little cumbersome was "I find it to recommendable to clear the object before returning unless.... ", I think it might have been more clear if you flipped it around - "If you haven't transferred ownership, then I find it recommendable to clear the object before returning". Someone new to rvalue references may not have picked up on the "unless" conditional if they were busy processing everything else. Keep up the amazing content
@Bisqwit
@Bisqwit 5 жыл бұрын
Yeah, despite my best efforts in editing the narration carefully before recording to ensure clear delivery and concise expression, often I fail to spot some good ways for rephrasing things. Thanks anyway!
@JonBlanton
@JonBlanton 5 жыл бұрын
Rest of the video is on point! English is my native language and I’m not even half as articulate as you lol #mentoringgoals
@kostax4489
@kostax4489 5 жыл бұрын
That chart basicly explained my entire c++ course
@ethanmccue7942
@ethanmccue7942 5 жыл бұрын
I really liked both the content and the format of this. Thank you for spending the time to make this video!
@MusiCrazyEsperanza
@MusiCrazyEsperanza 3 жыл бұрын
That example at 2:00 is the first time I've laughed while learning anything related to programming. GG +10 will see again
@averron82
@averron82 5 жыл бұрын
Great video, thank you. The only thing I'd mention is that pass-by-value needn't always be expensive with complex objects - notably when the object supports move construction (such as most of the standard library containers) and the caller passes an rvalue to the function. Passing by value and moving inside the function can actually be more efficient than passing by const lvalue reference when you need to store something and still allow the caller to pass both lvalues and rvalues, because you'll at least avoid the copy in the latter case. This can make it a great choice when writing constructors which store their complex parameters as member variables.
@Bisqwit
@Bisqwit 5 жыл бұрын
Pass by value but invoke by rvalue reference - that is indeed a possibility I had not considered at all. However, I fail to see the advantage of that over just using rvalue reference to begin with. If we create a test and compare the compiler output of these two cases, we see the way of using rvalue reference is much more efficient with fewer temporaries, even if the contained data is indeed constructed only once. godbolt.org/z/YsPNIm And if you need to also support const parameters etc., then the universal reference (not addressed in this video) trumps all of them, seen in the third example.
@averron82
@averron82 5 жыл бұрын
@@Bisqwit Yes, I don't disagree - if you absolutely know that the caller will be passing an rvalue (or want to force them to do so), then taking an rvalue reference is the best choice. I'm simply saying that if you're writing a function (or particularly a constructor) which you want to be callable with both lvalues and rvalues - and if the intended purpose of that function is to store a copy of the thing passed to it - then taking the parameter by value may be better than taking a const lvalue reference. Another option would be to provide overloads of your function, but that's going to cause a combinatorial explosion when you have multiple parameters. Forwarding (universal) references are a great option too, but not appropriate under all circumstances (for example a virtual function). I've put together a short example here: godbolt.org/z/aA_xjN, but I'd also recommend this talk by Nicolai Josuttis which covers the topic in a lot of detail: kzbin.info/www/bejne/hn-1m6hslN6hadE
@averron82
@averron82 5 жыл бұрын
I do want to disclaimer that though by saying I really am thinking specifically about constructors, not 'setter' functions. The reasons get a little complicated, but basically come down to types which allocate some internal buffer and only reallocate if a value is assigned to them which exceeds their existing capacity (for example, std::string). There's some discussion of this here: kzbin.info/www/bejne/rp_UhX56bdp3bJY
@sleepyy8782
@sleepyy8782 5 жыл бұрын
Teacher: There are 2 ways to pass variables to a function *bisqwit* : wrong
@srccde
@srccde 5 жыл бұрын
Your teacher is not actually wrong since lvalue and rvalue references are still just that: references. The difference between them is entirely resolved on language level as their distinction is based upon the type system of C++.
@torchmusic27
@torchmusic27 5 жыл бұрын
Get that milestone! Another great and useful video. Though my favorite Bisqwit videos are the longer, scripted ones creating a larger application, like the 3D engine in C or the roguelike game in C++.
@SoftBreadSoft
@SoftBreadSoft 5 жыл бұрын
I dont know if I have a favorite kind of video. Everything you make is very watchable
@SoftBreadSoft
@SoftBreadSoft 5 жыл бұрын
My favorite individual videos are probably the 360 degree compiler series and the speech synthesizer
@h65119
@h65119 5 жыл бұрын
Actually i love your programming content in general, I learned and still learning new things from you
@a544jh
@a544jh 5 жыл бұрын
Great work! This may be the best explanation I've seen about this concept.
@Bisqwit
@Bisqwit 5 жыл бұрын
Thank you!
@SimGunther
@SimGunther 5 жыл бұрын
The best cutaways of any programming video
@DiegodeSousa
@DiegodeSousa 5 жыл бұрын
That’s a pretty cool initiative! Thanks for share your knowledge with us. Cheers
@cmdlp4178
@cmdlp4178 5 жыл бұрын
My favorite videos on your channel are the videos about creating a compiler.
@lorenzoiannuzzi3937
@lorenzoiannuzzi3937 5 жыл бұрын
I love how the guy was photocopying a Math HL book.
@unevenprankster
@unevenprankster 5 жыл бұрын
There is no better day than a Friday afternoon with your coffee and a new video from Bisqwit teaching me stuff.
@HorochovPL
@HorochovPL 5 жыл бұрын
You taught me some useful things. I've never heard before about && (except logical and). Sets, deques and other std data containers - seen it used by You and I googled it, very useful things.
@eizooW
@eizooW 5 жыл бұрын
I enjoy your programming livestreams the most
@o_klk
@o_klk 5 жыл бұрын
It's nice to see this in 4k 60fps :)
@iurycabeleira7990
@iurycabeleira7990 5 жыл бұрын
I dont even program and im subscribed to your channel. Thats just how good you are! 😬
@steven1671
@steven1671 5 жыл бұрын
Is it true that the compiler will turn a pass by value parameter into a reference or even a move if copying the argument is unnecessary?
@Bisqwit
@Bisqwit 5 жыл бұрын
Sometimes it might, but more likely the opposite can be true, and even then only in inline contexts and compilation-unit local contexts. It cannot break APIs.
@krisnaresi623
@krisnaresi623 5 жыл бұрын
Please make tutorial about smart pointer. This tutorial is awesome.
@ashrasmun1
@ashrasmun1 5 жыл бұрын
why do you need another tutorial if there are already tons of them on the net?
@krisnaresi623
@krisnaresi623 5 жыл бұрын
@@ashrasmun1 Likewise this Parameter Declaration tutorial right? There's already tons of them but I like how Bisqwit do it by using nice analogy and clear explanation.
@multirampage1
@multirampage1 5 жыл бұрын
Can anybody explain why test = val at 5:00 does not clear val? (i.e not call the move constructor)
@Bisqwit
@Bisqwit 5 жыл бұрын
Because a named variable is never automatically a rvalue reference. It is a lvalue or const reference instead. Only a temporary, such as the return value of a function, is automatically a rvalue reference. You can turn named variables into rvalue references by casting, and the standard way to do that is to use the std::move helper function. That is why test = std::move(val) would call the move-assign, while test = val calls the copy-assign.
@multirampage1
@multirampage1 5 жыл бұрын
@@Bisqwit Thanks!
@KishoreG2396
@KishoreG2396 4 жыл бұрын
Instead of using references, hypothetically, I wonder what would be the performance benefit/loss from making all function parameters value by default and simply passing in parameters using std::ref and std::cref (std::reference_wrapper objects) instead.
@Bisqwit
@Bisqwit 4 жыл бұрын
That’s just a rube-goldbergian way to accomplish the exact same end result. godbolt.org/z/-G_72z Literally exact, not a single instruction of difference (as long as the code is present in the same compilation unit).
@SuperArjun11
@SuperArjun11 5 жыл бұрын
I haven't done anything big with cpp, is the rvalue reference used regularly for production code? I don't see any advantages to it, why not just one of the other methods?
@Bisqwit
@Bisqwit 5 жыл бұрын
Yes, it is used regularly in production code. Its advantage is firstly that it documents the intention, as any source code should strive to do first and foremost. Intention being, passing the ownership of data. Secondly to that end it can uniquely be used in some situations where none of the other solutions accomplish the same thing. For example, you cannot use lvalue references with temporaries. Const references and by-value do not permit making modifications to the original variable. Pointers cannot be used with temporaries either.
@DusanFajler
@DusanFajler 5 жыл бұрын
First watch: "sweating and rewinding trying to understand" Second watch: "Ah, oooh, ooooooooh"
@kelvinvalencio2
@kelvinvalencio2 5 жыл бұрын
Hello, I just wanna say that I enjoyed this video very much and you should be making more noob-friendly tutorials like this.
@idiosinkrazijske.rutine
@idiosinkrazijske.rutine 5 жыл бұрын
Bisqwit v.s. The Tech Lead? My head will explode
@akj7
@akj7 5 жыл бұрын
What i ask myself, when i write a TRIVIAL function in Python: 1. How should the function be called? 2. What parameter should we give in What i ask myself when i write a function in C++ 1. What should the function return? 2. What should the function be called? 3. What arguments does the function take? 4. Are the passing on the arguments optimal? 5. Should the function be const? 6. Should the function limit the throws (noexcept()) 7. Should the function be inlined? 8. Am i overriding some other function? 9. Should i use reference qualifiers?
@pepe6666
@pepe6666 5 жыл бұрын
java is easy: all objects are pass by reference, all primitives are pass by value. thats even easier than python
@avimalka5362
@avimalka5362 5 жыл бұрын
Great video ! My 2 cent, much better then watching you light speed programming. Really hope to see more tutorial videos.
@BrendanMcDonnell149
@BrendanMcDonnell149 5 жыл бұрын
Beautiful and clear flowchart. Is there some way we can download it?
@Bisqwit
@Bisqwit 5 жыл бұрын
Here: i.imgur.com/dFDGT42.png It’s transparent though.
@Moco26
@Moco26 5 жыл бұрын
When you have no clue about c++ but you love watching (listening to) bisqwit
@BlackHermit
@BlackHermit 5 жыл бұрын
An excellent video. Greetings from Sweden!
@Fezezen
@Fezezen 9 ай бұрын
This video made me think about how often I just end up using pointers instead of references in my code, but I think I'm too lazy to bother refactoring.
@grproteus
@grproteus 4 жыл бұрын
5:35 - this chart is the reason why C++ is not just difficult to learn, it's also difficult to read and maintain. Love it, but it is a mess. This is also why many C++ codebases will end up relying on pointers - change the declaration of a function and you have to do weird refactoring to all the code that calls it - and the code around the code that calls it.
@zohichnazirro8640
@zohichnazirro8640 5 жыл бұрын
Can someone tell me which compiler he uses in his videos?
@neloka4313
@neloka4313 5 жыл бұрын
I love those illustrative clips!
@WhatzHappeningNow9
@WhatzHappeningNow9 5 жыл бұрын
Someday I wish to be at least half as good as Bisqwit
@SapphFire
@SapphFire 5 жыл бұрын
So this is what the community post was for. The real life examples were a great idea. One thing I didn't understand though was "[Pointers] are pretty much deprecated in C++". Aren't C style arrays passed with a pointer?
@Bisqwit
@Bisqwit 5 жыл бұрын
The statement about the deprecation was in the context of giving a called function access to your variable, like transmogrify(&myvariable); Yes, all the C-style stuff basically makes an exception.
@SapphFire
@SapphFire 5 жыл бұрын
@@Bisqwit Ah, okay. Thanks for the explanation.
@iProgramInCpp
@iProgramInCpp 5 жыл бұрын
The way you say ubiquitous Where did you get those illustrations?
@Sukigu
@Sukigu 5 жыл бұрын
I really enjoyed your Cracking Videogame Passwords series. The couple of videos on linguistics also captured my interest, since I really like that subject too.
@AmineZyad
@AmineZyad 5 жыл бұрын
Hello Bisqwit, can I use That Terminal in my mac machine ?
@Bisqwit
@Bisqwit 5 жыл бұрын
I don’t know.
@koodauskanava9096
@koodauskanava9096 5 жыл бұрын
It would be nice to see some beginner friendly c++ content. All these topics and videos are out of my level to actually learn anything.
@Bisqwit
@Bisqwit 5 жыл бұрын
This video is aimed at beginners and intermediate, though.
@gregandark8571
@gregandark8571 5 жыл бұрын
*Bisqwit im waiting for your Talmud about C++*
@namesurname201
@namesurname201 5 жыл бұрын
Hi there, what's ur editor, is it vim? if so how did u do look like that?
@Bisqwit
@Bisqwit 5 жыл бұрын
The editor is Joe, as shown on the screen in plain text almost the entire video.
@namesurname201
@namesurname201 5 жыл бұрын
@@Bisqwit I see thankss for answering
@littleampton2
@littleampton2 5 жыл бұрын
Thanks, finally it's all clear!
@Davi-c4q
@Davi-c4q 5 жыл бұрын
How much faster is std::move compared to simple pass by reference?
@Bisqwit
@Bisqwit 5 жыл бұрын
They are exactly as fast. Neither actually _does anything._ They are syntax semantics with different implications, and different applications.
@1schwererziehbar1
@1schwererziehbar1 5 жыл бұрын
const pass by value is also allowed, but I'm not sure what it does.
@Bisqwit
@Bisqwit 5 жыл бұрын
Mentioned in an annotation at 8:18 in the video. Const pass by value is exactly the same as regular pass by value, except that the function is barred from making changes into the copy of the variable it receives.
@mllarson
@mllarson 5 жыл бұрын
I like your cracking passwords videos and videos like this. Also your insane "Let's do 16 color OpenGL in an emulated Linux on DosBox on Linux" videos.
@Bisqwit
@Bisqwit 5 жыл бұрын
Thank you for sharing your thoughts!
@ShanyGolan
@ShanyGolan 5 жыл бұрын
there are many other cracking videos out there... go study!
@jxsl13
@jxsl13 5 жыл бұрын
super good video. A little sensory overload. I'd say as a constructivee criticism, smaller steps, slower, less visible stuff on one slide. If someone wanted to learn more, they would want to see it properly and not super fast as ir's done here. If someone wanted to recall stuff they already know, they would like it this way, super fast(less of a tutorial character?)
@Bisqwit
@Bisqwit 5 жыл бұрын
That’s because this video is halfway between an introductive tutorial and a reference manual. A reference manual is something you get back to, pause and study in detail, while an introductive tutorial is something that paints broad strokes and goes over the big picture in a palatable fashion.
@valizeth4073
@valizeth4073 5 жыл бұрын
How come that you're using .cc and .hh instead of .cpp and .hpp ?
@Bisqwit
@Bisqwit 5 жыл бұрын
I like that better.
@valizeth4073
@valizeth4073 5 жыл бұрын
@@Bisqwit Why though?
@Bisqwit
@Bisqwit 5 жыл бұрын
Shorter, and not the least bit less expressive.
@TheHippyhopp
@TheHippyhopp 5 жыл бұрын
Are pointers really useless in C++ unless you have to use them??
@Bisqwit
@Bisqwit 5 жыл бұрын
99% of times people use pointers in C++ it’s because they don’t know C++ well enough, or they come from backgrounds like Java where the word “new” (allocates a new instance) is the bread and butter. I should make a video about this.
@PJBoyYT
@PJBoyYT 5 жыл бұрын
Great video, will definitely be my first point of reference to aide people who suffer from learning C++. My only gripe with the video is where you talk about clearing the moved-from vector in the rvalue reference example without mentioning that this only applies to vectors and it's not a weird member function that suddenly exists for rvalue references (I'm fairly sure this will be a point of confusion for some of the people I'm imagining). Furthermore, the C++ standard already guarantees that a moved-from vector will be cleared for all non-C++-guru cases ( stackoverflow.com/questions/17730689/is-a-moved-from-vector-always-empty/17735913 ), and even C++-guru cases in GCC
@Bisqwit
@Bisqwit 5 жыл бұрын
It exists for all std containers from lists to priority queues, not just vectors, and by clearing I don’t mean specifically calling a method named clear(), but I mean the meaning of the English word. Clear the object. And yes, the C++ standard guarantees that. I know that, and I did even imply that in the code comments. If you read the code comments (and listen to the narration at 5:00), you see that I suggested explicit clearing only if it was not already done by moving the data away.
@PJBoyYT
@PJBoyYT 5 жыл бұрын
Actually priority_queue et al don't have clear() methods. None-the-less, on rewatching, I can see that I was mistaken in interpreting what you meant when you said to clear the object, and I apologise for not reading the code comments. Also upon rewatching, I noticed that clearing the vector in this case *was* explicitly needed because you are assigning new data to the rvalue reference, which would otherwise persist after returning. I honestly have never even considered that a vector that I moved into a function call parameter could return non-empty, so thanks for the lesson! Please keep up the good work ^_^
@Bisqwit
@Bisqwit 5 жыл бұрын
I stand corrected, priority_queue and stack do not have a clear() indeed. But list, vector, map, set, unordered_map, unordered_set, deque, forward_list, and basic_string, do.
@kyzsAllIn
@kyzsAllIn 5 жыл бұрын
glad to see you back :)
@aibou2399
@aibou2399 5 жыл бұрын
loved this video
@gchinmayvarma9030
@gchinmayvarma9030 5 жыл бұрын
Oi @Bisqwit , your thoughts on Python?
@Bisqwit
@Bisqwit 5 жыл бұрын
Probably the best interpreted (as opposed to compiled) language, if its applications are considered.
@gchinmayvarma9030
@gchinmayvarma9030 5 жыл бұрын
@@Bisqwit Do you code in python often? If so will you ever upload things related to it? I'm in love with your videos and I'd love to watch something i could understand more :)
@Bisqwit
@Bisqwit 5 жыл бұрын
I think I have only ever written one program in Python. bisqwit.iki.fi/src/btfriend.py This one, somewhen in 2004.
@johanandersson8464
@johanandersson8464 5 жыл бұрын
A video with several statements about C++ and the comments are not all "Well, actually..." What's going on here?
@notsoclearsky
@notsoclearsky 5 жыл бұрын
Man, how can you program in that near text editor like ide? Just download visual c++
@Bisqwit
@Bisqwit 5 жыл бұрын
Why would I.
@notsoclearsky
@notsoclearsky 5 жыл бұрын
@@Bisqwit it's just much more convenient and fast. It's will boost your productivity.
@Bisqwit
@Bisqwit 5 жыл бұрын
Yeah sure(!)
@kuchenzwiebel7147
@kuchenzwiebel7147 5 жыл бұрын
Although I write in c++ I like the c style pointers better.
@Veso266
@Veso266 5 жыл бұрын
is this video a consequence of your submission when you asked couple of monthe ago for people to hold something and send you their videos?
@Bisqwit
@Bisqwit 5 жыл бұрын
Your wording makes it impossible for me to answer yes, but this video _is_ why I posted the community challenge asking for submissions. You can see this sheet for the scripts of the clips that I was asking for. docs.google.com/spreadsheets/d/1LqbPTT07lvtK6cIuSunJOzoXecWAaXOZvQfmikaodTY/edit?usp=sharing
@xthomas7621
@xthomas7621 5 жыл бұрын
Pass By Value: Oh ok i get that Pass By Reference: Hmm, Ok, I get that too. Pass By Const Reference: Huh? Ok, it can't change the data. Double Ampersand: Wait what did this do again? Everything else: I need to rewatch the video, don't I. Nice video though. What is Joe's own editor, your own app?
@Bisqwit
@Bisqwit 5 жыл бұрын
Joe is joe-editor.sourceforge.io .
@walkwithme153
@walkwithme153 5 жыл бұрын
We need party , when you hit 100k. Yay!! :D
@alex0flex378
@alex0flex378 5 жыл бұрын
3:07 I'm not sure this is accurate (or at least with the Microsoft C/C++ compiler v19.16). This code compiles and runs just fine. #include #include #include std::vector getStrings() { return std::vector({ "str1", "str2", "str3" }); } void printStrings(std::vector& strings) { for (std::string str : strings) { std::cout
@Bisqwit
@Bisqwit 5 жыл бұрын
I have subtly censured MSVC on a number of occasions in my videos. Microsoft is not exactly known for making standards-compliant products. Thank you for proving again why my criticism is justified. Spot the odd one out: godbolt.org/z/pofGJD
@Bisqwit
@Bisqwit 5 жыл бұрын
Note that if you add the /Wall compiler option, MSVC at least gives you the warning that teaches you the true state of your code: “warning C4239: _nonstandard_ extension used: A non-const reference may only be bound to an lvalue”. Another good reason to always compile with warnings on.
@alex0flex378
@alex0flex378 5 жыл бұрын
@@Bisqwit Thanks for the quick reply! I didn't know that!
@RamkrishanYT
@RamkrishanYT 5 жыл бұрын
Can you point out learning resources for c++?
@Bisqwit
@Bisqwit 5 жыл бұрын
Learning? Don’t know, sorry. Reference? I use en.cppreference.com/w daily.
@gregandark8571
@gregandark8571 5 жыл бұрын
www.ntu.edu.sg/home/ehchua/programming/cpp/cp10_io.html
@konstantinrebrov675
@konstantinrebrov675 5 жыл бұрын
I like watching Bo Qian on KZbin
@MrAlzPatz
@MrAlzPatz 5 жыл бұрын
Great vid
@JaskoonerSingh
@JaskoonerSingh 5 жыл бұрын
Thanks for that. A real help
@gubx42
@gubx42 5 жыл бұрын
I hate pass by lvalue, I prefer pointers. The reason is that I don't expect functions to modify arguments. If I need an output, I make it explicit using &. There are some drawbacks to pointers but for me, the pros outweigh the cons.
@43ann
@43ann 5 жыл бұрын
Is it me or are there some problems with the audio?
@Bisqwit
@Bisqwit 5 жыл бұрын
What kind of problems?
@Bisqwit
@Bisqwit 5 жыл бұрын
Well, we don’t know what he referred to. In any case, those clicks that you mention are _probably_ caused by the kdenlive-multirender.sh script which splits the rendering timewise into chunks that are concatenated. I have suspected this may cause glitches.
@43ann
@43ann 5 жыл бұрын
@@Bisqwit Hey! Ethan Ansell nailed it! I am referring to those clicks. But they are very sparse throughout the video. I am not saying the video is unwatchable or anything. I just noticed the glitches. Great video btw. :-)
@ShanyGolan
@ShanyGolan 5 жыл бұрын
text to speech voice vs. Bisqwit voice ... Bisqit wins hehe
@gavinridley5727
@gavinridley5727 5 жыл бұрын
I’ve been using pointers in my C++ code, and had no clue they were frowned upon! Looking into this, I see why. Thanks!
@lukefitzpatrick398
@lukefitzpatrick398 5 жыл бұрын
They're not frowned upon, not sure how you got that from this video.
@gavinridley5727
@gavinridley5727 5 жыл бұрын
@@lukefitzpatrick398 "They are pretty much deprecated in C++" at 7:45. The definition of deprecate is "express disapproval of", btw.
@lukefitzpatrick398
@lukefitzpatrick398 5 жыл бұрын
@@gavinridley5727 Fair point, I will rephrase what I said to "whether or not they are frowned upon is a matter of opinion" lol. Sweeping generalisation to say that pointers are pretty much deprecated.
@gavinridley5727
@gavinridley5727 5 жыл бұрын
@@lukefitzpatrick398 Seems that's the consensus for modern C++. The standards committee has set out on this (jk, but the post does justify their deprecation): www.fluentcpp.com/2018/04/01/cpp-will-no-longer-have-pointers/ Unfortunately I work with people who still use fortran, so whether something is modern isn't particularly relevant. xD
@CapteinObvious
@CapteinObvious 3 жыл бұрын
@@gavinridley5727 The article you linked is an April's fool's joke. I'm not sure how you or anyone else got the idea that pointers are deprecated or going away. Especially since they have been expanded with smart pointers in modern C++. I think it's pretty misleading of bisqwit to claim that pointers are more limited than references considering that references themselves are just const pointers under the hood. Pointers are not always safe but they are powerful, flexible and in my experience absolutely essential in modern C and C++ programming. They are nether frowned upon nor being deprecated any time soon.
@pepe6666
@pepe6666 5 жыл бұрын
oh man i came here because i was confused. i left even more confused. thank you though this is a great reference. i think im going to curl up into a ball and die. also +1 for joe editor
@Bisqwit
@Bisqwit 5 жыл бұрын
Let me know if there is something specific you’d like me to clear up.
@pepe6666
@pepe6666 5 жыл бұрын
@@Bisqwit oh wow thank you bisqwit. i think i'll be fine its just a little over my head :) I will come back later when im more familiar with C++ and wanting to get into pointers more in depth. thank you though you're a champ
@jakio6750
@jakio6750 5 жыл бұрын
time to build up that kernel
@CurrentlyObsessively
@CurrentlyObsessively 5 жыл бұрын
You know as much about passing values as I do about the whole C++ language.. Self esteem minus 2.
@Bisqwit
@Bisqwit 5 жыл бұрын
There is no shame in being a beginner and admitting it.
@CurrentlyObsessively
@CurrentlyObsessively 5 жыл бұрын
@@Bisqwit I will just have to study harder! :)
@1red114
@1red114 5 жыл бұрын
haha, now you have actors for programming show
@Bisqwit
@Bisqwit 5 жыл бұрын
I figured it’s better if I ask for community contributions rather than try to do those entirely myself.
@mysticbatch6265
@mysticbatch6265 5 жыл бұрын
Should i learn C or C++?
@Bisqwit
@Bisqwit 5 жыл бұрын
Maybe both, in that order!
@davidporterrealestate
@davidporterrealestate 5 жыл бұрын
More please!!!
@konstantinrebrov675
@konstantinrebrov675 5 жыл бұрын
Where is your accent from?
@leonhrad
@leonhrad 5 жыл бұрын
Just make everything a global variable and you'll never have to pass any parameters to your functions.
@Chiarettoo
@Chiarettoo 5 жыл бұрын
That's the spice
@KishoreG2396
@KishoreG2396 5 жыл бұрын
YES! While we're at it, let's put all our code in main() and use goto's to different parts to simulate function calls without actually creating a function. Genius!
@LasRozasDeMadrid
@LasRozasDeMadrid 5 жыл бұрын
@@KishoreG2396 Basic is the perfect language!
@anatolydyatlov963
@anatolydyatlov963 5 жыл бұрын
@@KishoreG2396 Actually, let's write the whole code in __asm { };
@KishoreG2396
@KishoreG2396 5 жыл бұрын
@@anatolydyatlov963 I've got one even better. Program an entire NES emulator using everything in _asm{ }... ...on a single line.
@JohnDoe-fw3lw
@JohnDoe-fw3lw 5 жыл бұрын
gem
@sabriath
@sabriath 5 жыл бұрын
I'm old school, there are only 2 types of declarations.....by value, and by reference, that's it. Also, the function can do with the variable whatever it wants, when you pass stuff to it, it belongs to that function now....just saying. Anything else is just fluff for garbage collection and people who don't know how to program....me? zero errors, zero page faults, and zero memory leaks in all of my code in the 26 years I've programmed.....just saying. I feel like the bad guy on GalaxyQuest, when he says "Am I to believe a Captain doesn't know every bolt and every weld on his ship?".....because if you program something, you should know EVERYTHING your program is doing at EVERY moment in time, down to the machine code.....that's old school, and that's how you program error free.
@mllarson
@mllarson 5 жыл бұрын
So you've never made a mistake EVER, even when you were first learning? Bullshit. Pull the other one while you're at it.
@konstantinrebrov675
@konstantinrebrov675 5 жыл бұрын
You've been programming for 26 years? Just curious, how old are you? Also how old were you when you first started programming? How did you get so much experience?
@sabriath
@sabriath 5 жыл бұрын
@@mllarson , I'm what they call a "prodigy"....I see things differently when I am programming, so yes, I've never made a mistake.....at least, not at the finish line. Obviously as I am programming, I notice things will go wrong before I even finish a function, then I fix it right then and there before I move onto the next function, but published works never had errors.
@sabriath
@sabriath 5 жыл бұрын
@@konstantinrebrov675 .... I've been programming since I was 9, learned every programming language by the time I was around 12 years old, even designed my own microprocessor around that age as well (that's what they used to call a CPU before they became powerful). I don't know why it came to me, I've always had a thing for it, started out on commodore 64. I usually stick to backend stuff, like networking, AI, drivers, etc...but would love to build games, never learned the discipline (just a hobby for me).
@x0j
@x0j 5 жыл бұрын
the duke nukem engine video duhhhh
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 843 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Texture Mapping & Polygon Rasterizing Tutorial (1/2) [C++20]
22:46
How I got Mario in That Editor - And how Norton Got 🐁
13:30
Forbidden C++
33:07
javidx9
Рет қаралды 1 МЛН
Emulating a CPU in C++ (6502)
52:28
Dave Poo
Рет қаралды 1 МЛН
What is mathematical thinking actually like?
9:44
Benjamin Keep, PhD, JD
Рет қаралды 16 М.
Hash Tables and Hash Functions
13:56
Computer Science Lessons
Рет қаралды 1,6 МЛН
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 984 М.