I'll be spending the next few weeks watching your videos and brushing up my C++ skills. Thanks for sharing your knowledge!
@MuletTheGreat10 ай бұрын
How did you brushing up?
@LucidStew7 жыл бұрын
Even though it got a bit off topic, I like the "you could do this, you could do that" part with using and typedef while explaining the use of auto to do something similar.
@andrefaustino55142 жыл бұрын
TIP: In current MVS2022, if you double click left ctrl, the inferred type will be displayed between auto and the name. It's a great tool for those who really wants to know the type of the variable but also wants a cleaner code. It's like you can alternate between inferred type and explicit type with one button.
@wang_76652 жыл бұрын
That's why I love this series so much. Firstly learned from the video itself, then learned from comments to grab new features.
@yousefbilal4837 Жыл бұрын
This has been updated to alt+f1 instead of double ctrl in newer versions
@AgentM1247 жыл бұрын
I use auto to drive to my work
@will80907 жыл бұрын
I use my drive to auto work
@pixarfilmz47697 жыл бұрын
I auto drive my work to use
@marcdroz33696 жыл бұрын
auto_comment(!=creative){};
@bluehornet67524 жыл бұрын
My auto broke, so now I can't work...
@massiveblackwood4 жыл бұрын
I work auto to drive home
@reshmamundamkotil71265 жыл бұрын
I feel blessed for finding this channel. Thank you man. I mean a lottttt.
@vivekkoul44283 жыл бұрын
Hi how far have u reached with C++ now that it's already 2 years passed
@theguywhoiscoding99126 жыл бұрын
you can simplify the for-loop even more to: for (auto &string : strings) readability over 9000
@emilianzawrotny3675 жыл бұрын
It is better to do for(const auto &string : strings)
@Alberto-ez4lr4 жыл бұрын
@@qatarking2498 means that you are using a reference of a string instead of making a copy of each string object for each iteration, that's would be so inefficient.
@adesva4 жыл бұрын
He mentions for-range loops in the video and says it will be covered later in the series
@arthur11121324 жыл бұрын
@@qatarking2498 & used at variable declaration is the 'reference' token in C++ In addition to the C 'get adress of' meaning everywhere else. so here, 'auto &string' means declare a variable reference of automatic type named "string" :) also, i think a for-range loop would have been a bad example of what he wanted to demonstrate since in that case, 'auto' refers to 'std::string' and he wanted to show how long an itterator can be
@shutout9513 жыл бұрын
Be careful that you don't write that loop when using namespace std; then you'll be overriding the name of the string variable inside the for loop.
@dordan99874 жыл бұрын
15:00 How I feel about c++
@godnyx1174 жыл бұрын
LMAO!!! 6 months later, how you feel now?
@AgentM1244 жыл бұрын
@@godnyx117 You know why programmers have 2020 vision? It's cause they C++
@apotheos47833 жыл бұрын
I still don't feel what you feel.
@adryelgainza15303 жыл бұрын
Almost a year. How are you now?
@moonyl53416 ай бұрын
4 years later, do you still agree?
@izukaa5 жыл бұрын
Hey, theCherno! Greetings from Romania, you're my first choice when comes to C++ tutorials. Nice job!
@mogovanjonathan4 жыл бұрын
la fel))
@christ47917 жыл бұрын
You know the day is gonna be good when cherno uploads a video
@silurust4 жыл бұрын
Good explanation. Good guideposts. I can still remember a long cursing session from an experienced C++ programmer colleague when C++11 came out. When we asked why, the short answer was: "auto". His opinion was that the possible abuse significantly outweighs the benefits. (Perhaps, by time, he stopped having allergic reactions.)
@robertmoats18903 жыл бұрын
I'm a huge typedef fan when templated code results in messy or confusing typenames. I don't use auto very often, but I do like your usage for iterator typenames. In those cases, the auto keyword is unlikely to get you into any trouble. I think in most other cases, it actually IS likely to get you into trouble. It is a useful tool to help dig your own grave.
@syirogane2 жыл бұрын
I like "auto" (and its variants in other languages) for when the actual type is of little or no interest to me (though I generally avoid it for basic types), and the times the actual type is of no interest is when the algorithm itself is far more important than the actual types involved. Also, "auto" should be considered mandatory when the type is explicit elsewhere in the line (result of a cast, new, etc), but I don't consider 5.0 or 5f to be sufficiently explicit.
@michaelwplde4 жыл бұрын
11:00 Careful there, not sure whether constness, references i.e. & amp, are not conveyed in raw auto usage. 13:30 Exactly...
@abbudeh7 жыл бұрын
Thanks for your great explanations. It would be great if you talk about lambdas and assertions in C++14 :)
@VasaMusic4386 жыл бұрын
again a great episode !! clear and full of real code experience !! Thank so much!!
@leixun4 жыл бұрын
*My takeaways:* 1. *auto* could automatically work out what's data type suppose to be 0:11 2. When we might not want to use *auto* 5:04 3. A better way to use *auto* 8:58
@reynep11 ай бұрын
Should be pinned
@AnimeKing-m2t4 ай бұрын
How can I click "Like" on all your videos at a time? Because your way of explaining the concept is so lucid that I can easily conclude I'm gonna like all your videos..Hands down 🙌
@JayAnAm5 жыл бұрын
Nice explanation. One other use-case for auto is when migrating your C++ application to 64 Bit I would prefer auto over types like unsigned int that could behave in a different way for 32 Bit vs 64 Bit compilation.
@keris39204 жыл бұрын
Use size_t for this. That is its purpose
@rastaarmando70584 жыл бұрын
just use int64_t bro.
@michaelwplde4 жыл бұрын
1:40 auto for lambda variables is tremendously helpful... But if you need a specific base template type, might not be a good use for auto.
@maishamolepo22164 жыл бұрын
Really good video. A suggestion on what to make next: Data structures 😀
@koungmeng5 жыл бұрын
std::unordered_map is just like a dictionary in python. That means it contain key , values pair: eg: std::unordered_map dict={ {"one",1}, {"two",2}}; std::cout
@rastaarmando70584 жыл бұрын
thanks man.
@smileynetsmileynet79224 жыл бұрын
I know a lot about C++, but still some stuff like auto is new. My BIG use so far of it, is to create a language. This language will later have so much features that it needs to have multiple languages to describe it, probably.
@vadiks200323 жыл бұрын
as far as i understand programming is a big thing and you can't just learn C++ in 2000 and never ever learn anything new, because there are gonna be updates, there are gonna be new libraries, and other stuff. so it is not weird its new for you even though you know lots about C++
@miteshsharma31067 жыл бұрын
Talking about templates ..... You said there will be many more videos on templates ... you could make that next !!
@tahamagdy49326 жыл бұрын
SimGunther Hello Haskeller :D
@jerfersonmatos284 жыл бұрын
Thay are in the game engine series
@OmarAbdelaziz__475 жыл бұрын
two years ago of creating this video. Happy new year cherno!
@DanielLiljeberg6 жыл бұрын
I was just about to write that auto is so nice when working with itterators for crazy collections :)
@arthur11121324 жыл бұрын
I personally prefer to use 'auto' only in prototyping and research purpose. When I tests some stuff, 'auto' is kind of a quick way to do and try stuff. But once i finished to test and i'm actually working on a real project, i do preffer to use real types (or typedef/using for types that are really long or that mignt change in a future version). Also, typedef helps to change a whole ABI as well, but still restraining varibles to a single type. So changing types remains really easy that way :)
@Adam_Lyskawa2 жыл бұрын
That seems quite useful for prototyping. You know, a quick and dirty, short piece of code as POC, test if an idea works, then replace "auto" with proper types.
@Daniel-q6x2s2 ай бұрын
I aspire to make a list of all Charno's 'don't-use' coding styles and request a code review from him.
@MsJavaWolf6 жыл бұрын
I also really like knowing my types and being explicit. Many people think C++ is too verbose, but I think it helps in bigger projects. In languages like Python you will often see a ton of comments instead, telling you what types a function is expecting etc. I quickly becomes as long or longer than C++ code, which is self documenting to a certain degree.
@simonmaracine47215 жыл бұрын
Or just use type hints instead of comments.
@Favo524 жыл бұрын
So when looking in a map this would be a good use too? auto it = map.find(x); if (it != map.end()) // do something
@annsgal20252 жыл бұрын
The main reason I don't use auto is because it makes it impossible to detect integer overflows. I only use it for iterators.
@GenjaOrigins3 жыл бұрын
I wish you teach hashMap HashSet etc i see some so difficult examples and some simple ones
@PerchEagle5 жыл бұрын
I like the different possible options to do something ! so I can use auto, typedef or even define ! but auto is a nice feature and it absolutely simplify things. Like small embedded projects that are easier to debug and also with using it, the code would be less prone to have errors or warnings.
@clemenswolfbartl51384 жыл бұрын
As a Kotlin developer, I have to say this is not an issue to not specify the type and just infer it, from the perspective that you can't read the type when you take a look at the declaration. The IntelliJ Idea has a feature that lets display the inferred type (in Kotlin). There is maybe a plugin to let display the inferred type in visual studio. This is more an tool problem than a language feature problem.
@andrefaustino55142 жыл бұрын
I don't know before but, in MVS2022, if you double click ctrl it shows you the infer type before the var name, just like IntelliJ. I think C++ devs have a tendency of been extra careful with types, for understandable reasons, but auto can be helpful for a cleaner code.
@Brahvim3 жыл бұрын
Smart pointers, and here we have these. _They're slowly making it JavaScript 🤣_
@aritzh7 жыл бұрын
I know you would probably not use smart pointers, but what would you write: std::unique_ptr obj_ptr = std::make_unique(whatever); auto obj_ptr = std::make_unique(whatever); I am asking because std::unique_ptr is not that long, but for me it seems quite redundant, since the std::make_unique already tells the exact type
@rj00a7 жыл бұрын
I think most programmers would use auto there.
@vhxhao4 жыл бұрын
Will there be a performance difference between actual type and auto keyword?
@nonnullptrhuman5042 жыл бұрын
I don't think so.. Because the type is always known at compile time.
@berktopbas14963 жыл бұрын
I cannot get the deduced "auto" type(int,char etc.) by compiler with mouseover in VS code(3:00) Is it an extension feature?
@StevenMartinGuitar2 жыл бұрын
You have to decide whats the biggest time saver....not typing the huge data type three times in your code.... or not having to play Sherlock whenever you maintain the code or explain it to others
@alexissuarezalvarez56224 жыл бұрын
can auto replace template? hi, can auto replace template? i am new to c ++ :(
@CoolModderJaydonX Жыл бұрын
I usually just use auto for function pointers or something where I don't know what the type is.
@ShNeoteric4 жыл бұрын
So auto is like the var variable in c#?
@ChopsTwo7 жыл бұрын
I think a better rule of thumb would be that you should specify the type explicitly when you need to know the type explicitly, and use auto when you don't, which is almost all the time really. It's still a strongly typed language, so the compiler will still make sure everything is correct. The idiom of using auto is common enough in the C++ community that it has a name, AAA, or Almost Always Auto. A real benefit to using auto even when the type is short is that implicit conversions are not allowed - so if the API changes and you have auto, there won't be unnecessary conversions all of a sudden, where there might be if you specified the type manually. Not a whole lot can be done to address the problem of needing to manually look up the type when you use auto, except that in my experience, it's much rarer to need to do that than it would seem at first glance. My recommendation would be to give both my and Cherno's strategies a go and see which you like - it really isn't *that* important which you choose. It will probably come down to what kind of work you do. I've done a lot of refactoring, and when a code base doesn't use auto, it tends to become a mindless task of changing the type to match the new type when auto would have just worked correctly, as well as unintended performance and correctness bugs from surprising type conversions that auto would have avoided.
@billybollockhead56282 жыл бұрын
On my team, we have a rule. If you use Auto, you need to have a VERY VERY VERY good reason to do so. As, personally, I like "self documenting" code, where I can debug something sometimes just by following it through. Usually, I can spot a bug just because auto has been used (coder thinks its a float, but it's an int, or something)
@anthonyduran26273 жыл бұрын
bless yo intelligent, puzzle solving soul
@hvvijuka2 жыл бұрын
you are really good in C++ thanks
@ankitjayswal51833 жыл бұрын
So when do we use & with auto?
@meer_kat51583 жыл бұрын
Hi char *GetName() { return "Hello"; } this is a bot confusing. Won't this be destroyed when the scope ends? Can you return a pointer to an array on stack? Can you please explain how can a function return reference? It is very confusing.
@GuruPrasanna2 жыл бұрын
'auto' isn't "type erasure" but "type INFERENCE". I see it as a convenience feature. C++ is still very strongly typed. It is just that you don't need to specify the type in places where the compiler can infer it. For C++ to lose its strong typing, you should be able to use "auto" for function params in its signature, or member variables. You can't.
@EvilSapphireR2 жыл бұрын
I don't see any way a compiled language can ever be weakly typed.
@Gojam122 жыл бұрын
My compiler disagree's with the char* returning a "Cherno". Any ideas why. I assume its because I am on a different C++. I believe I am on C++13 but not sure. In fact it causes two errors one on name.size() and the other on the char*.
@grzegorzdomagala99293 жыл бұрын
auto is a blessing - espacially when you need to declare iterator for std::list of std::map - and thank the holly c++ standard committee for "for(auto a : list) :)
@Vermilicious4 жыл бұрын
Anything that is implicit is sort of bad, because it assumes some additional knowledge, and you have to think about multiple things at the same time when looking at it. Auto is such a thing, and the pointer-to-char constructor of the string class is another, which is mentioned in this video. I would just avoid these things if possible. I think perhaps they introduced auto to make the language seem more appealing compared to loosely typed languages, but if they really wanted to allow loose typing in C++, they should've tried to get rid of the auto keyword entirely (which would break a lot of things). I suspect auto will end up on lists of regret eventually.
@edwinmartens74592 жыл бұрын
I NEVER use things like auto (or var in C#) Why ? Auto location = GetLocation(); So tell me, what is the type of location in this statement? That is why !
@GenjaOrigins3 жыл бұрын
ordered unordered map videos please sir Di Cherno!!!
@enjoylife65434 жыл бұрын
Great tut! 8:06
@spwim4 жыл бұрын
could auto be interesting when doing math-functions on mathematical operations? auto SomeFunction ( auto aNumber, auto anotherNumber){ auto result = do some fance math; return result; }
@Keregosh4 жыл бұрын
Pretty sure you would use templates for that instead
@AyushSingh-lo4qo4 жыл бұрын
I think there would be a problem with this even if it does work in precision or simply deducing the type. Because of the different number of trailing points, Or even in big numbers where if a double and a double are multiplied and return type is an int we lose precision.
@YourMaster0003 жыл бұрын
What is ur laptop specs
@544mamama4 жыл бұрын
1:24 am not gonna take 10 mins *takes 17 mins
@ImNotGam Жыл бұрын
I think the only time I've ever used auto is when I used auto specifically just so that I could use auto because I never had before. I very quickly changed it away from auto because it didn't help anything at all.
@spwim4 жыл бұрын
could auto be interesting when doing math-functions on mathematical operations? Like you could pass either doubles, floats, or ints to them? auto SomeFunction ( auto aNumber, auto anotherNumber){ auto result = do some fance math; return result; }
@gtrsteve9 ай бұрын
That is a sutuation for templates... :)
@urduislamicstatus21074 жыл бұрын
your english is amazing
@xzy71964 жыл бұрын
Why wouldn't it be? Like he is English.
@amarbs32874 жыл бұрын
Is this done during preprocessing stage or compilation stage
@theserghd13 жыл бұрын
you didn't mention that 'auto' is necessary for lambda declarations
@prashantdhonde78914 жыл бұрын
Does auto helps in better memory management?
@fipabrate7 жыл бұрын
i use auto to declare a lambda functions
@eddyecko945 жыл бұрын
Normally use it with templates if the there's a possibility of different return types.
@nathandecena76946 жыл бұрын
So, i can determinate that keyword in C++ is like keyword in C#, JS, and now JAVA10? Am i rigth?
@nathandecena76946 жыл бұрын
Peterolen Thanks
@yunhuaji30383 жыл бұрын
What's the plug-in/extension that you use to show the actual type of auto when hovering the cursor on the variable? Is it available for VScode on macOS? Thanks!
@Xiefux3 жыл бұрын
it works for on vscode on linux
@BobChess11 ай бұрын
Auto in C: 😭 Auto in C++: 🗿
@violinsheetmusicblog5 жыл бұрын
Can you make a video on iterators?
@katewolf003 жыл бұрын
so basically, auto in C++ is like var in javascript where it chooses the type for you? neat
@MicheleGobbato714 жыл бұрын
The Playlist for the C++ series is disappeard :-(
@laike9m7 жыл бұрын
Can you make a video about move semantics?
@alltheway994 жыл бұрын
Done 🙂
@GenericPhantom12 жыл бұрын
Auto automatically figures out what the variable type is supposed to be.
@zyghom2 жыл бұрын
all was ok until probably episode 40-50, now it is becoming ... too fast and too difficult ;) still 50 to go
@casperes09124 жыл бұрын
Instead of having to write string you can write auto... Fantastic... You save 2 chars. With int you even use extra chars. A keyword like this has its uses but if you're declaring an int... Just declare the int. If it is absolutely assured to stay an int at least
@lotrbuilders50413 жыл бұрын
That works great, if you’re only using strings and ints. And you’re sure your interface will never change type and your not using lambdas
@andregoulbourne8393 жыл бұрын
Very helpful, coding in java and needed a little translation.
@Krokoklemmee7 жыл бұрын
will you also cover decltype(auto) at some point in the future?
@platin21487 жыл бұрын
OtakuNewb As it is part of the language surely.
@Mental-Walk3 жыл бұрын
Another great video brother. But you missed the fact that we can't use auto without initializing it(I think). Thanks for the great series.
@Mental-Walk3 жыл бұрын
@Borislav Kamenov it's interesting. But how?
@Mental-Walk3 жыл бұрын
@Borislav Kamenov Yeah brother, C++ does not allows to use it without initialisation.
@mrboyban3 жыл бұрын
Great video, it is basically like an automagic.
@Theawesomeking44443 жыл бұрын
so its basically How to turn C++ into Python
@pranavraja90453 жыл бұрын
nr
@alltheway994 жыл бұрын
Is that a Pixel 2 XL next to you on the couch ? 🙂
@erwinschrodinger23203 жыл бұрын
Great!
@soniablanche5672 Жыл бұрын
typescript and rust developers would use it all the time lol
@hawks31093 жыл бұрын
You should avoid auto unless it's very obvious what the type is. Auto can make mistakes and it's not obvious to the next programmer what the type is supposed to be. It goes against strongly typed language ideology. This is kind of like a dynamic type during compile time.
@Maikie-s8o6 ай бұрын
i love chernos video, love from China
@Kapil_Thakar2 жыл бұрын
I am gonna watch all videos!!!!
4 жыл бұрын
The only place I use auto is in ranged for loops, simply because it is idiomatic.
@matt-g-recovers4 жыл бұрын
Result!
@Hazit906 жыл бұрын
thanks for the video. You answered a few questions :)
@nicholasrobinson187 жыл бұрын
If you had to do something like this (I know this code is rubbish and shouldn't be a thing, but it demonstrates my question): for (auto i = 0; i < someList.size(); i++) // Do something in the loop What would happen if you there was more than 2147483647 (max int) items in that list? Would it remain an int and just overflow or would it become a long (or something else bigger than an int)
@rj00a7 жыл бұрын
the variable 'i' is guaranteed to be constructed as a signed int, so it would overflow (assuming it's 4 bytes). But if you did auto i = 0u or unsigned i = 0 'i' would be constructed as an unsigned int, and you would have twice the capacity to work with. I would personally just do unsigned i = 0; or maybe even size_t i = 0, depending on the situation.
@beaverundercover34792 жыл бұрын
Thanks. For the time being as a beginner auto adds a layer of opacity and is therefore best avoided.
@KillzoneKid7 жыл бұрын
Making vid about auto and not mentioning lambdas is a crime! ;)
@alexjustmd7 жыл бұрын
Killzone Kid because templates ftw;)
@AmeshaSpentaArmaiti7 жыл бұрын
he's probably building up to it. he only introduces one concept per video. which is fine, since people wanting to learn about auto don't automatically want to learn about lambdas. i, for instance, use auto to skirt around the stl's seeming hatred for memorable names.
@TheCherno7 жыл бұрын
Yes, good point! I'll definitely mention that in the lambda video. :)
@heisenburger3114 жыл бұрын
It's not smartly auto, since it could not infer reference type even when the function returns a reference.
@heisenburger3114 жыл бұрын
@Peterolen Thank you a lot for mentioning decltype(auto)!
@zantazanta29063 жыл бұрын
Thanks for your good job
@anonymous-vj7jk3 жыл бұрын
thank you very much
@fishyperil21537 жыл бұрын
I was hoping you'd talk more about the "dark side" of auto ^^ you know, the stuff you mentioned in the end , how it can work with templates etc. But the video was still pretty useful . Up to now whenever I came across code that used auto I was never really sure what the reason for using it was. This helped clarify that a lot of it is just for convenience purposes.
@mmaranta7854 жыл бұрын
You’re the best
@lavi11724 жыл бұрын
very good video. thank you!
@manzoorahmed60486 жыл бұрын
Which software should I used for C++ programming? ?? Which software you are using