How I use C++: a line-by-line code review

  Рет қаралды 247,455

strager

strager

Күн бұрын

Пікірлер: 388
@wildmushroom2452
@wildmushroom2452 Жыл бұрын
Just found your channel and I have to say, I could sit and listen to you for hours, you are very articulate and explain things very nicely. Defiently sticking around for a while since I have picked up C++ recently!
@strager_
@strager_ Жыл бұрын
Cool! Follow me on Twitch if you want to listen to me for hours.
@doublegdog
@doublegdog Жыл бұрын
This is the type of video i love to watch. Raw explanation and code and no fluff. You just won another sub!
@jimmydandy9364
@jimmydandy9364 Жыл бұрын
Indeed a good video to watch if you have insomnia and can
@edmunns8825
@edmunns8825 Жыл бұрын
@strager I just found your channel, I watched this video the other day. I'm learning C++ at the moment coming from a C background. Just wanted to say this is the best video I've seen for just going through and talking about code structure and why you do certain things and don't do others. I found it really helpful.
@strager_
@strager_ Жыл бұрын
You're welcome!
@orestes_io
@orestes_io 9 ай бұрын
This is the perfect video for someone with enough experience looking for a tour of actual C++ code and not just cookie cutter tutorials. Super valuable! Thank you :)
@disgruntledtoons
@disgruntledtoons Жыл бұрын
Font choice: The most important features are that the numeral 1 and the lower-case l are readily distinguishable, and that the zero and the capital O are distinguishable. Your IDE should alert you to these things. Also, it's interesting how so many of the problems we struggle with in C++ in 2023 are the result of choices that should have been made when C was first developed.
@allNicksAlreadyTaken
@allNicksAlreadyTaken Жыл бұрын
The point people make oftentimes is not to never use raw pointers, but to never use *owning* raw pointers. And I find it to be very beneficial to me.
@strager_
@strager_ Жыл бұрын
Good distinction! Yeah, I generally agree with you about trying to not use owning raw pointers. I'm not 100% sold though.
@puppergump4117
@puppergump4117 Жыл бұрын
@@strager_ I made a library that uses raw pointers and I changed it to smart pointers to fix something. The smart pointers honestly provided nothing useful. From within the library, there's no need to either take ownership of or use reference counting for an object. I don't really see any situation where you would lose track of something so much that you can't tie its destruction to whatever is using it or explicitly destroy it. For those reasons, since raw pointers are not only easier to work with but also don't cause unexpected behavior by mangling your objects, and because they do the exact same things, I say smart pointers are dumb.
@XD82ful
@XD82ful Жыл бұрын
​ @Pupper Gump For a small project not using smart pointers is usually not a problem, though I would still recommend it. If working on any larger project it helps a lot. When working with raw pointers you need to be very careful taking everything into consideration and if the project is large that can be very difficult. For example if you have a class that has a raw pointer which it owns and the destructor is responsible of deleting it. Do you every time remember to implement the copy, move constructors and assignment operators to make sure nothing bad happens or at least mark them as deleted. And even if you do this it is a lot unnecessary work. If you instead used unique pointers then copy constructors would be implicitly deleted(you can explicitly define it if you really needed it) and move constructor is implicitly defined and it uses the move of the unique pointer. So in case you don't need to do anything special you don't have to define any of the constructors, assignment operators and destructor and you are guaranteed to not have a memory leak and everything with out writing a single line of code. Also declaring pointer as unique pointer indicates clearly which object owns it and is very useful for others reading the code to know who owns it. In general when you see unique_ptr you know you own it and when you see * you know you are borrowing it from some other object. And in case unique pointers are not enough, that is there is no clear owner of the pointer then using shared pointers instead of raw pointers becomes even more important. Handling the raw pointers and doing some sort of manual reference counting to make sure when to delete the pointer is prone to errors if you ever forget to decrement the count you run into a memory leak and in some cases these can be very hard to find especially since they can happen only in very rare cases that are hard to reproduce. Shared pointers are not going to solve everything as they have their own issues like circular references, so you have to still be careful when using them but at least you have one degree of freedom less to keep track of. And if you consider the performance I doubt there is going to be a situation in which using smart pointers is going to be (significantly)slower compared to using raw pointers. Unique pointer is more or less zero cost while shared ptr keeps reference count but you most likely would anyways need to keep it up by your self. And in that special case where the almost non existent performance benefit matters, is most likely some algorithm that is only a very small part of the code in which case I suppose you could consider not using smart pointers, and even in that case I would profile whether it has any benefit. Anyhow you should always use unique_ptr whenever it is possible. If you need shared_ptr try to think if you can do something to only need unique_ptr and if it seems completely impossible then use the shared_ptr. There are also different types of smart pointers but in case you need to use those(or raw pointers) the architecture is probably not very good at that point(maybe in some case you could actually have some good reason to use them but unless you can tell a very good reason to your self: why you need to use them, why nothing else works and why nothing can be done differently then you shouldn't)
@puppergump4117
@puppergump4117 Жыл бұрын
@@XD82ful In my case, smart pointers appear unnecessary for a lot of the pointer operations I'm doing. My project is a gui, so I take objects the user instantiates and store their pointers inside a vector of pointers. On top of that, an object's pointer can also be held by another object through binding, which might be a good case to use shared pointers without ownership. On top of that, to make creating new objects easier, I give objects a vector to store their own instantiations of other objects, which is then accounted for in the update/draw loop. Because of all of this, I've created many functions to abstract any pointer operations. And I haven't had any issues with them for a long time. I think what you're talking about are projects that use many classes from many libraries and the programmer really just mixes them together, but my case is just using one specific library and adding on top of it. Of course, maybe I'm gonna regret using raw pointers in the future, but here's the project if you really wanna tell me off: github.com/PupperGump/gui/tree/master/gui
@XD82ful
@XD82ful Жыл бұрын
@@puppergump4117 I took a quick look and I think you are basically thinking of a different thing here takin a reference like for example having Button b; Object* o = &b; is not actually something where you need a smart pointer, here the memory is in stack and it cannot even leak as it will be released as it goes out of scope. By not using smart pointer one means that you directly do something like Object* o = new Button(); so that you are dynamically allocating memory and you need to release it by calling delete o; In these cases instead of using new and delete you want to use smart pointers in which case you would have something like std::unique_ptr oo = std::make_unique(); this creates object in dynamic memory using new internally and then releases it using delete internally without you having to call it explicitly. So basically using raw pointers is fine even if you are using smart pointers(and in fact necessary) the point is that you won't call new and delete by your self. And in above example you can get the raw pointer by calling oo.get() which returns Object*. Anyways good luck with your gui project :)
@apolloapostolos5127
@apolloapostolos5127 Жыл бұрын
This whole video was one rabbit hole after another, for me. . I think it’s helping to get me up to speed with the programming skillsets.
@fano72
@fano72 11 ай бұрын
Awesome channel, top work! I'd love to watch all your videos since I have the time.
@AaroRissanen-pi4td
@AaroRissanen-pi4td 6 ай бұрын
This video was a goldmine of professional and robust practices. Thank you very much, I learned many a new thing!
@strager_
@strager_ 6 ай бұрын
You're welcome. I hope you don't borrow my bad practices too! 😆
@michaelfekadu6116
@michaelfekadu6116 Жыл бұрын
Very cool walkthrough! Definitely a little bit insane, but aren't we all a bit insane in our own ways ;) Thank you for the delightful view into your coding workflow!
@malusmundus-9605
@malusmundus-9605 Жыл бұрын
Nice vid man- very cool to see someone be honest about what's working and what's not with their setup/code. Oftentimes I see programmers (especially young ones) assert that everything they are doing is correct and if you do it differently you're just plain wrong.
@strager_
@strager_ Жыл бұрын
My style evolves with every project.
@LeadingNPC
@LeadingNPC Жыл бұрын
Good comment.
@xit
@xit Жыл бұрын
The legend is back!
@joeybasile1572
@joeybasile1572 7 ай бұрын
Nice video. Very interesting perspective. Thank you for your time.
@TerjeMathisen
@TerjeMathisen Жыл бұрын
You seem to care about performance, so just a small tip which I discovered when I updated my old word count (wc) utility to count utf8 letters instead of bytes: Casting the input array to signed char allowed me to detect all follower bytes with (c < -64) instead of checking two boundaries (c >= 0x80 && c < 0xC0). Next I split the processing into chunks of 128 bytes (or any other small multiple of 16) and stored the count as a byte: At this point the autovectorizer would generate pretty much perfect code, i.e. 16-byte (or 32 for AVX2) loads, followed by a simd compare and a simd subtract (since the compare results are -1,0 instead of 1,0). It ran in ~0.3 clock cycles/byte.
@strager_
@strager_ Жыл бұрын
> Casting the input array to signed char allowed me to detect all follower bytes with (c < -64) instead of checking two boundaries (c >= 0x80 && c < 0xC0). That's pretty cool! Clang does this optimization, but GCC doesn't: godbolt.org/z/rGGjdK7xo
@TerjeMathisen
@TerjeMathisen Жыл бұрын
@@strager_ Yeah, I am using Rust on Windows and since MSVC can compile with either their own or the Clang back end, I believe that is what I'm seeing. (I use cargo-asm for disassembly listings)
@MrAbrazildo
@MrAbrazildo Жыл бұрын
18:24, I agree. I think outside is prone to errors, because it can be called in an unexpected situation, which currently you are unaware. Before lambdas, I rather even make it a macro, to use inside the f(), only, and #undef it right after the f(). Although I relax if the f() is called by more than 1 f() - this case, it's not technical internal complexity, it has probably a higher-level meaning. 21:20, nowadays, MemorySanitizer catches this. 23:20, I benchmark Clang vs GCC on switch vs if-block vs array vs bitfield. Sometimes 1 was better for some cases, other for other cases.
@bluefal
@bluefal Жыл бұрын
your code is amazing and fabulous!!!
@spacemonky2000
@spacemonky2000 11 ай бұрын
The most impressive part of this video is your control over Vim
@MaxCoplan
@MaxCoplan Жыл бұрын
While I know comments are normally suboptimal, I might’ve put a comment at 37:00 explaining what `size` meant in this case. Or add a comment on the definition of the struct, but if `size` doesn’t always mean how much you skip then I’d just put above line 96 in this file
@strager_
@strager_ Жыл бұрын
Yeah, my util/utf-8 module does need to be improved. Same with every other module... 😅
@channel-so2st
@channel-so2st Жыл бұрын
What roadmap / books would you recommend to learn modern C++ for an intermediate Python / Kotlin programmer? Don't want to risk reading a 1000 page book that teaches bad habits
@strager_
@strager_ Жыл бұрын
I recommend against roadmaps. I suggest picking a project idea and working on it.
@arashiryuu1624
@arashiryuu1624 Жыл бұрын
Would it be possible to get that selection/range highlighting where the token colour gets taken in and used as the background colour in VSC?
@strager_
@strager_ Жыл бұрын
I don't know about Visual Studio Code extensions, sorry. Maybe it's possible with a color scheme.
@silicondecay
@silicondecay Жыл бұрын
I like the syntax highlighting, makes it a lot better imo. Also would find it pretty hard not to have go to definition/implementation/type definition. I use neovim with all this. I could live without auto completion though
@blacklistnr1
@blacklistnr1 Жыл бұрын
Came here from you big O video where I thought you were programming in Comic Sans, but it looked monospace so I brushed it of as my imagination. It's nice to know it actually was a Comic inspired font and that I'm not going mad.
@strager_
@strager_ Жыл бұрын
Yup, it's Comic Code. I love it! tosche.net/fonts/comic-code
@MrAbrazildo
@MrAbrazildo Жыл бұрын
51:20, although I'm not a fan of vertical code, this is a good exception: - The vertical alignment allows to quickly spot some errors, like lack of bits, even if an operator disalignment was seen 1st, for instance. - Double click in a keyword, and all its occurrences on the block will appear, helping spot errors too - _if the code editor has this feature_ . - The single line would be too large. I use to go towards the right margin, using commands of the "same kind": variable declarations (of any type), tiny lambda definition, loop-if-consequence ("same thing" to me), and so on. 52:17, auto can be: - "Refactorer": if the returning type ever changes, you don't need to hunt its occurrences. - Defensive: avoids you from mistaking the returning type, getting an inplict conversion, which can lead to problems. - Elegant (at least I think so): getting "the same face" for declarations. I have been using it on all places, like a rain, and curiously I'm not running into issues.
@Katniss218
@Katniss218 Жыл бұрын
I find auto (or var in C#) very hard to read. It's very often not clear the type that is returned, and I prefer not having to hover over every identifier to see it.
@MrAbrazildo
@MrAbrazildo Жыл бұрын
​@@Katniss218 In this case, when the f() is already fixed, auto may be replaced by a typedef. But when the f() is being developed, auto is more productive. Btw, its absence for return in Carbon is my main complain against the new language.
@henka4166
@henka4166 Жыл бұрын
at 17:38, about pointer aliasing: can't this also be solved by doing it in pure C and using restricted pointers?
@strager_
@strager_ Жыл бұрын
I'm in C++, not C, so no 'restrict'. Even if I had 'restrict', I cannot use 'restrict' on struct members. Often I use pairs of pointers (e.g. a source_code_span has a begin and an end), and 'restrict' is not allowed for those kinds of things.
@allNicksAlreadyTaken
@allNicksAlreadyTaken Жыл бұрын
Usually structs are classes without invariants and when I hear struct, I assume it has no invariants, i.e. it's just a bunch of data without methods that do anything overly interesting or complicated.
@bsgamer5069
@bsgamer5069 Жыл бұрын
Your voice is so good it always help me fall asleep.
@strager_
@strager_ Жыл бұрын
I'm sorry that I am so boring 😭
@bsgamer5069
@bsgamer5069 Жыл бұрын
@@strager_ You voice is absolutely amazing.🫀
@jbooks888
@jbooks888 Жыл бұрын
I'm so glad I only write programs for myself, some simple and less than a thousand lines of code and others with tens of thousands of line, BUT apart from a couple of small business friends, I'm the only one who uses them. And I've used Visual Basic 6 and Access Databases for all of them and they are plenty fast enough! With the ability to write your own User Controls, the maintainability and convenience is amplified even more. But, I don't need it to be accessible to any other coders and I don't need it to run on anything but Windows.
@strager_
@strager_ Жыл бұрын
Yeah, portability is a small burden but it's all over my code. =\
@alurma
@alurma Жыл бұрын
Clangformat: I exist to solve formatting problems This video: is about formatting problems :D
@ItzAnameOk
@ItzAnameOk Жыл бұрын
1h and 40m of Strager? Yes pls. Also, nice shirt
@AlexSav
@AlexSav 5 ай бұрын
Usually C++ code is ugly. But this one is just outrageous. Make a custom execution with UB ( 1:35:26 ) and be proud of it
@berkaybakacak
@berkaybakacak Жыл бұрын
I don't know you, KZfaq just recommended this video. And, I liked your environment
@ihatethewind
@ihatethewind Жыл бұрын
You are sooooo close to Unix beard! Keep going!
@MrAbrazildo
@MrAbrazildo Жыл бұрын
1:14:00, I rather a compact block of declaring f()s: - Blank lines become begin/end of a block section, which is much more meaningful than just separating cmd lines. - Result in compact code, which raises the likelihood of fitting the block in a screen. - According to Kate Gregory, who worked "rescuing abandoned projects" (due to lost of control over them): _"Those blank lines dividing sections of code help us a lot! Please use them."_ (for this propose). 1:26:09, the Codeblocks IDE I use puts a comment after the #endif, referencing its #if argument. It's handy when the block is big.
@strager_
@strager_ Жыл бұрын
> 1:26:09, the Codeblocks IDE I use puts a comment after the #endif, referencing its #if argument. It's handy when the block is big. Yeah, that does sound super handy! Code Biscuits does this for many languages in many editors: github.com/code-biscuits/
@tabletuser123
@tabletuser123 Жыл бұрын
This thumbnail is a mood
@MattXChrist
@MattXChrist Жыл бұрын
I looked at this code for two seconds and dipped… this is one way to give your senior software engineers a stroke
@codahighland
@codahighland Жыл бұрын
When it comes to identifier style, I follow Qt's style guide. The fact that this largely agrees with most other modern languages (C# choosing to use initial caps on functions and properties is annoying) is a plus, even though I was using C++ first. (I learned C++ in 1997. The keen-eyed among you may notice this is before the language was standardized.) This has become mildly irritating as C++ gets better and Qt starts using more out of std::, but what can you do?
@yogxoth1959
@yogxoth1959 Жыл бұрын
I really wanted to see how you navigate the codebase without LSP and such, do you talk about that at all in this video? I don’t see anything in the chapter titles.
@strager_
@strager_ Жыл бұрын
I didn't talk about code navigation in this video. (I think...)
@marioc485
@marioc485 Жыл бұрын
Great Video :)
@metin4yt
@metin4yt Жыл бұрын
37:18 why do you prefer to have an if/else when you return in the if? Dropping the else would reduce the nest level
@strager_
@strager_ Жыл бұрын
In this case, I think it's easier to read similar code if they're at the same nesting level.
@mattshu
@mattshu Жыл бұрын
I am in love with the monospaced Comic Sans. I feel like society would shame me but I can't look away
@liquidsnake6879
@liquidsnake6879 3 күн бұрын
use what you like, screw what other people think, they're not the ones staring at it 10 hours a day
@simplepycodes
@simplepycodes Жыл бұрын
Very nice! impressive.
@PeteBrubaker
@PeteBrubaker 3 ай бұрын
35:30 - I like that style a lot. It really helps when learning unfamiliar code, or when you inherit something and the original author is long gone.
@GrindAlchemyTech
@GrindAlchemyTech Жыл бұрын
🧑🏽‍💻Thanks this was great🏆
@Heyim18bro
@Heyim18bro Жыл бұрын
I didn't realize I cared so much about font until I saw this, this font would drive me crazy :x
@vytah
@vytah Жыл бұрын
This kind of font is very readable, I use Fantasque Sans Mono for the same reason. Many "normal" programming fonts have characters that look too samey, made of repeating identical angles.
@Heyim18bro
@Heyim18bro Жыл бұрын
@@vytah i can't get with it, i feel like there's a lot more fonts that are easier to read but i'm not one to care for them too much; that being said I would care if this was the font set and switch it to something else xD
@oldnews4160
@oldnews4160 Жыл бұрын
@strager - In your opinion, what are the uses for a programmer nickname? In this case, it's not for anonymity. Follow up question, Is it something you would like to be called in the workplace or just by friends? Thank you for this video and your content. Much appreciated. I enjoyed this one particularly and seeing your take on C++.
@strager_
@strager_ Жыл бұрын
If you are referring to 'strager', I consider that my name, not a 'programmer nickname'. > Follow up question, Is it something you would like to be called in the workplace or just by friends? I go by 'strager' everywhere not-legal, but sometimes I use 'Matthew' if I think someone would have a hard time pronouncing or remembering my name. (I should get around to changing my legal name...)
@oldnews4160
@oldnews4160 Жыл бұрын
@@strager_ lol That'd be awesome. Thank you for the reply. Just curious is all. The more I get into programming, web development, and showcasing my projects I have been considering adapting a media name of sorts or alias. I have seen cybersecurity professionals and hackers also use tech names for anonymity, but I have yet to think of a name. In college I had a nickname from friends, but other than that I have had no other aliases other than just youtube or video games. I constantly change these names though, there hasn't been one alias I've stuck on. Again, thank you for the reply, I appreciate you.
@PeteBrubaker
@PeteBrubaker 3 ай бұрын
Have you switched to polyglot or tree-sitter for your syntax highlighting yet? It's so worth it.
@mikeharry1799
@mikeharry1799 Жыл бұрын
regarding usage of raw pointers: use them when you don't care about ownership; so an owning class uses unique ptr, but when passing it to other functions for usage it should just pass raw pointers or references
@sourestcake
@sourestcake Жыл бұрын
At the start, the assert in the 'byte' lambda is incorrect. It's off by one.
@strager_
@strager_ Жыл бұрын
You're right! I'll fix it. Classic off-by-one error. github.com/quick-lint/quick-lint-js/commit/e9fccba1f9f842dab130f559e0562a0e40a1542a
@sqwert654
@sqwert654 Жыл бұрын
Was wondering what font you use, 49secs in I got an answer. I use MS Comic Sans (since the 95 odd) for the same reason. I find it very readable and natural. But the one your using looks better.
@strager_
@strager_ Жыл бұрын
Comic Code: tosche.net/fonts/comic-code
@sqwert654
@sqwert654 Жыл бұрын
@@strager_ cheers have already bought and installed in Rider. Looks very readable.
@piotrek7633
@piotrek7633 Жыл бұрын
i dont understand anything what the hell is going on
@neur303
@neur303 Жыл бұрын
When I use CamelCase, each block only contains 1 uppercase letter that way it is mappable to the subset of lower snakecase. i.e. not HTTPWriter but HttpWriter would be equivalent to http_writer.
@strager_
@strager_ Жыл бұрын
blasphemy
@puppergump4117
@puppergump4117 Жыл бұрын
That is the only way to use camelcase.
@tissuepaper9962
@tissuepaper9962 Жыл бұрын
@@puppergump4117 nah, mixed-case letters in an initialism just looks so wrong. If something is common enough that you can use the initialism without a question of whether or not the reader will understand, then you can be assured that the reader will also be able to separate the blocks correctly. If you don't think the initialism is recognizable enough, don't use it at all.
@puppergump4117
@puppergump4117 Жыл бұрын
@@tissuepaper9962 Semantics are tough so here's the breakdown. When you use an ide, most of the time you will just type a few letters of the function or variable and hit enter to get the whole thing. The advantage of camelcase is that it lets you just say httpwr and it autocompletes. Or even htpwr. With snake case, you can only type a single word separated with underscores. So it would be http_wr instead. This is useful to filter out variable names such as members of classes.
@Zex-4729
@Zex-4729 Жыл бұрын
What are your thoughts on C++ core guidelines? I see you use orthodox(not 100% for your case) C++, I mean a lot of professionals still use orthodox C++ but will you guys ever get on to ISO C++ and C++ core guidelines? This is probably the larges rift in C++ community right now, everyone can write in their own sets of rules, It definitely has a benefit but it's also a problem right?
@defnlife1683
@defnlife1683 Жыл бұрын
Why is it a problem? Maybe an annoyance for a week or two if you move from one job to another while you learn the nuances, but that’s the same thing in every lang no?
@strager_
@strager_ Жыл бұрын
> This is probably the larges rift in C++ community right now The coding style things which the C++ core guidelines discusses are minor. Learning libraries (especially for concurrency) and the architecture is a much harder part of switching codebases than code style.
@strager_
@strager_ Жыл бұрын
> What are your thoughts on C++ core guidelines? The C++ code guidelines has good advice, but it doesn't change how I code much. Some advice, such as "ES.11: Use auto to avoid redundant repetition of type names" and "ES.20: Always initialize an object" and "ES.23: Prefer the {}-initializer syntax", are stupid. I tried it and didn't like it. Other advice, such as "ES.12: Do not reuse names in nested scopes" and "ES.26: Don’t use a variable for two unrelated purposes", is good and can sometimes be compiler-checked (thus enforced).
@Tyler11821
@Tyler11821 Жыл бұрын
@@strager_ I do like the auto style. Not for everything, but it's a consistent line style and you can specify type on the right side. Most code analysis tools can tell you the type if you aren't clear, and C++ doesn't have multi-line inference like rust. It _does_ decrease code changes needed when changing the type in other parts of the code base. I don't personally use {} for everything myself.
@tissuepaper9962
@tissuepaper9962 Жыл бұрын
@@Tyler11821 not a fan of needing IDE features to be able to tell what type is returned. I legitimately see no reason why you would want to abbreviate the function definition with auto. If you're in double-colon hell, use auto-complete or simplify the structure of your namespaces. Make a recognizable alias, if you don't like the other two solutions.
@felipemalmeida
@felipemalmeida Жыл бұрын
About the qualification of identifiers (where you actually talks about using multiple namespaces), you may actually have clashes with ADL, which is annoying. So, qualifying identifiers is a good thing for libraries at least where you don't know what else code may be included in the same translation unit.
@strager_
@strager_ Жыл бұрын
Yup! Luckily I don't have to deal with that much because I am making an application, not a generic library.
@rid9
@rid9 Жыл бұрын
How about ending type names with "_t"? decode_utf8_result_t, uint8_t, etc... It would make names consistent (decode_utf8_result_t decode_utf8_inline() { ... }) and wouldn't force you to think about how to capitalize acronyms (and would make it very easy to highlight as well).
@WoD2008
@WoD2008 Жыл бұрын
_t types are reserved by the POSIX standard and you shouldnt define your own to prevent future overlap in namrd
@rid9
@rid9 Жыл бұрын
@@WoD2008 Thank you for the comment, I didn't know that, I only knew about C's reserved underscore prefixes. I wonder if there are any other reserved naming conventions.
@strager_
@strager_ Жыл бұрын
I don't like it.
@dagoberttrump9290
@dagoberttrump9290 Жыл бұрын
@@WoD2008 That's a really unreasonable paranoia imho. If you happen to write a language feature outside of any namespace that happens to exactly match a future posix type and you hapoen to update to that posix standard, then you probably hit the 0.0001 percentile case. I would play the lottery with this kind of thinking. Besides, if you happen to declare the exact same type chances are you can now deprecate your own lib in favor of the new posix standard. Wouldn't it be nice if the compiler sends some error down the lines to inform you about this? Tldr; i use _t all the time, never had any hickups
@apasserby9183
@apasserby9183 Жыл бұрын
why name the type 'decode_utf_8_result' instead of 'decoded_utf_8_bytes'?. I am amateurish so may be missing something, but I think of verbs as methods ('decode') so would change to an adjective('decoded') and am not familiar with utf-8 so using 'bytes' helps me personally(not sure if it's helpful though). EDIT: understand better now, watched a bit longer and realized it's metadata of the 'decode_utf_8' method results, not the resultant bytes...
@strager_
@strager_ Жыл бұрын
> why name the type 'decode_utf_8_result' instead of 'decoded_utf_8_bytes'?. Your name makes sense, but when I see "bytes" I expect to see an array or something. I use [functionname]_result in a few other places in my code. It's a convention I picked up from somewhere and never noticed until you made me think about it.
@realisticlevel2553
@realisticlevel2553 6 ай бұрын
I would love a vid or stream about your general workflow😢
@hbobenicio
@hbobenicio Жыл бұрын
thoughts on #pragma once? very well supported by compilers, no need for header guards matching directories and filenames (which kinda eases refactoring of file names and dirs) and avoid's the need of a tooling script to fix it.
@hbobenicio
@hbobenicio Жыл бұрын
I'm a long time user of header guards, but recently changed to #pragma once. Just wanned to check if you see a reason for not to prefer it.
@strager_
@strager_ Жыл бұрын
For this project, I prefer to stick to standard C++ unless there's a good reason to deviate. I don't have any good technical to avoid #pragma once.
@isodoubIet
@isodoubIet Жыл бұрын
@@strager_ You'll intentionally invoke UB just to avoid exceptions but pragma once is too radical?
@Wren6991
@Wren6991 Жыл бұрын
This is good, clean code that I would be happy to work with or contribute to. Pragmatism over dogmatism, I like it!
@strager_
@strager_ Жыл бұрын
I wouldn't call it clean! 🤣
@thepirat000
@thepirat000 Жыл бұрын
God mode! ❤
@ajakororo5366
@ajakororo5366 Жыл бұрын
what do you do for go to definition?
@strager_
@strager_ Жыл бұрын
I don't. 😭
@strager_
@strager_ Жыл бұрын
Either I know what file the definition is (in which case I open that file and search) or I use a project-wide string search (which finds more than just the definition).
@rastaarmando7058
@rastaarmando7058 Жыл бұрын
@@strager_ Bruh, that's alot of wasted time.
@strager_
@strager_ Жыл бұрын
Yup.
@LorenMLang
@LorenMLang Жыл бұрын
Why not make char8 alias unsigned char when char8_t in unavailable? That should avoid all the casting issues.
@strager_
@strager_ Жыл бұрын
String literals are const char*, not const unsigned char*. 😬 But you do bring up a good point. I could use a string operator thingy to fix this problem... 🤔
@arnabthakuria2243
@arnabthakuria2243 4 ай бұрын
what font is this . Looks really good. Also great vid btw. learned a lot .
@PeteBrubaker
@PeteBrubaker 3 ай бұрын
That's like the first thing in the video, how'd you miss it? :)
@TheDriftingStig
@TheDriftingStig Жыл бұрын
My favorite part of this video is the Hooli shirt. Gavin Belson would be very proud. Where can I get this shirt?!
@strager_
@strager_ Жыл бұрын
It's a custom shirt. Not for resale!
@runtimejpp
@runtimejpp Жыл бұрын
this is good
@gerardsk8ordie
@gerardsk8ordie Жыл бұрын
omg I want your shirt!!!!!!!!!!!
@gblargg
@gblargg Жыл бұрын
7:14 For the header if you include it first this ensures that it doesn't have any dependency on other includes for it to compile. This is especially important in the library case you mention. 8:47 The point of namespaces is to avoid clashes and unwanted interaction with other code you have no control over. Making sub-namespaces like util adds none of this value because you're the author of all the code and can thus ensure it works well together in a single namespace.
@strager_
@strager_ Жыл бұрын
> if you include it first This is a good idea. However, usually my build system uses precompiled headers which makes you trick not work as desired. I've found it better to write a separate tool which #include-s all public headers and doesn't use my build system.
@strager_
@strager_ Жыл бұрын
> The point of namespaces is to avoid clashes and unwanted interaction with other code you have no control over. Exactly! I don't want *my* code having symbol collisions which I need to manually resolve. That's confusing!
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
​@@John-kd3bfWho hurt you?
@Hazanko83
@Hazanko83 Жыл бұрын
Really the only times that I use nested namespaces is to define a ''NAMESPACE_implem'' within the primary namespace that holds things not necessarily meant to be used as part of the public interface; usually something like a templated base class meant to be inherited and expanded upon, or free helper functions. In these situations, you can just add ''using namespace NAMESPACE_implem;'' within the block scope of your primary namespace and it won't leak out to elsewhere - and then you don't need to type NAMESPACE_implem when using that stuff in your intended-public-facing classes/functions. Technically yes, the primary purpose of namespaces is to help avoid naming collisions, and may very likely never be an issue in a personal project; but I think it's a good tool for organizing things, as well as removing clutter from the global or individual namespaces. Even in the situation of having multiple contributors, there is a big advantage in being more verbose/concise with naming and structure and what not. You can't ''using namespace'' in a class, but you CAN do it inside of a function. typedef's can also be quite useful, although slightly straying off topic maybe: ''typedef MyPersonalNameSpace::implem::MyClass_Base CLASS_BASE;'' and now you have an alias called CLASS_BASE for your more verbose alternative of a templated class that can be used anywhere the first one would have been used.
@Rust_Rust_Rust
@Rust_Rust_Rust Жыл бұрын
​@@sebastiangudino9377 who asked?
@ZiViZiV
@ZiViZiV 11 ай бұрын
Have you tried treesitter for highlighting?
@strager_
@strager_ 11 ай бұрын
Nope, not yet! I want to try it though.
@ZiViZiV
@ZiViZiV 11 ай бұрын
Just saying because of the highlighting issues you highlighted (scuze da pun 😅) Using treesitter solved some highlight issue I used to have on neovim.
@ZiViZiV
@ZiViZiV 11 ай бұрын
BTW, I am using the same font as you. I agree it is easier to read. Though I hope one day I'll have the time to patch it with my own handwriting LoL
@adamodimattia
@adamodimattia Жыл бұрын
I want this t-shirt!
@strager_
@strager_ Жыл бұрын
It's MINE!
@porky1118
@porky1118 Жыл бұрын
4:30 I always found it stupid to add the same copyright notice in every file. Even if one copies the code, they would not copy this message, would they?
@strager_
@strager_ Жыл бұрын
Copying a file is easier than copying a file + editing out the copyright notice.
@porky1118
@porky1118 Жыл бұрын
@@strager_ When I copy code, I normally remove the comments first, then reformat, then rename variables and functions so it's easier to understand for me, or to fit my coding style better, I also do a bit of small refactors in cases where I don't like their coding style or it's difficult to understand.
@bookle5829
@bookle5829 17 күн бұрын
There's a project, a serious project, that tries to remake comic sans. And the font looks cool imo. They're considering making the monospace version but they're busy with fixing the font.
@skeleton_craftGaming
@skeleton_craftGaming 3 ай бұрын
I would probably name decode_UTF_8_result the same as you (I may remove the _ between the F and 8) But if it doesn't have any acronyms in it, I would just use camel case If it's truly a helper function, having it defined as a lambda inside of the function that it's helping seems better to me ... You're supposed to use std: unique 11:16 And on top of that I'm not always looking at my source control, which is why putting some sort of identifier there is a good idea
@katanasteel
@katanasteel 17 сағат бұрын
If you have the short preamble at the top of the file, then have it add if missing at the end.... Or add the short license base on the LICENSE file in the root of the project. Sounds like a short little tool to write
@spikezlee
@spikezlee Жыл бұрын
all i want to know what IDE he is using ? and how is he so efficiency on the keyboard?
@strager_
@strager_ Жыл бұрын
Vim. I'm efficient after over 20 years of use and practice.
@MNbenMN
@MNbenMN Жыл бұрын
​@@strager_ I spent a year or two getting used to vscode instead of vim... but I still sometimes type :w in my files by muscle memory and sprinkle some extra "i" characters around
@amansagar4948
@amansagar4948 Жыл бұрын
How cool is this guy, i'll get anxiety working with this large of a codebase. Btw which keyboard is that?
@magetaaaaaa
@magetaaaaaa Жыл бұрын
It would seem that he truly is a C++ guru.
@kvbc5425
@kvbc5425 Жыл бұрын
27:05 literally me, the classic "it works for now" (i'm never going to fix it)
@anonimowelwiatko9811
@anonimowelwiatko9811 Жыл бұрын
if it works don't fix it
@cyrusol
@cyrusol Жыл бұрын
Why does your Vim logo kick the Neovim logo to the curb?
@strager_
@strager_ Жыл бұрын
I don't need no trendy bells and whistles!
@TheCodeVertigo
@TheCodeVertigo Жыл бұрын
Galvin Belson himself approved this code.
@greyfade
@greyfade 5 ай бұрын
At 28:30, you're expressing concern about "older compilers" and `char` vs `char8_t`.... Why? You're using designated initializers, which is a C++20 feature and requires a newer compiler _anyway._
@cloudstrife7083
@cloudstrife7083 Жыл бұрын
I agree with you on most of what you said what's your opinion about modern C++ and the zealot who think about doing just that and never use old c/c++ like you said earlier they think of never using normal old pointer or managing memory by hand etc I think it's starting to be a bit ridiculous etc... can't wait to see what A.I. will do to the field ...lots of devs are afraid of AI since they are just typing text in a file thinking about it
@____-pn8yb
@____-pn8yb Жыл бұрын
I prefer C, really. I like how GLib implements objects in C which can be called from C++. Also, I like the explicitness of manual malloc.
@cloudstrife7083
@cloudstrife7083 Жыл бұрын
@@____-pn8yb loool from what I understand and I read online now from C++ guru's most of the people who didn't move from C are dinosaur who didn't learn modern C++ correctly... who don't like change etc
@aingle4239
@aingle4239 Жыл бұрын
Love the shirt lol
@d0jackson
@d0jackson Жыл бұрын
love that shirt.
@codahighland
@codahighland Жыл бұрын
I forgot about the anonymous namespace thing. I would recognize it if I saw it, I know the semantics without having to think about it... But I could be using it in my code and I tend to forget. ^^()
@duartelucas5746
@duartelucas5746 Жыл бұрын
That shirt!
@wanfuse
@wanfuse Жыл бұрын
Put jump short hash/text above the copyright, so you can quickly get to it with a shortcut key attached to a find script? Obvious I know! Huge fan!
@strager_
@strager_ Жыл бұрын
Are you saying I should put the copyright stuff in a separate file, and just link to it from the top of the file? I could do that, but if someone copy-pastes the entire file into their project, the relationship is lost.
@wanfuse
@wanfuse Жыл бұрын
@@strager_ I was suggesting that you put a comment beneath your code that you put in all your code like a signature. Like #end-5437 , then put a shortcut key in your editor attached to find feature that automatically jumps to this code bottom rather than bottom of license which is after the code, simple and probably stupid for some reason I haven’t thought of, this assumes your editor supports macros
@arijanj
@arijanj Жыл бұрын
@@wanfuse you could jump to the end and scroll back once or twice
@pvt.ltd.yt_industries
@pvt.ltd.yt_industries Жыл бұрын
I lol's at the squirrel
@rankail
@rankail Жыл бұрын
Couldn't you make helper-functions static?
@rastaarmando7058
@rastaarmando7058 Жыл бұрын
A lambda that does not capture anything is stateless, so making it static is pointless.
@strager_
@strager_ Жыл бұрын
I could make certain helper functions static, yes. What advantage would that have?
@edgecrush3r
@edgecrush3r Жыл бұрын
10x for the Hooli shirt 😊
@trainerprecious1218
@trainerprecious1218 Жыл бұрын
can i steal his thread implementation?
@strager_
@strager_ Жыл бұрын
No. Stealing is wrong.
@MrAbrazildo
@MrAbrazildo Жыл бұрын
1:30:15, D.R.Y. assassination? 1:38:14, does deleting 'x' content is the same as 2 identical blocks? Will it execute 'X' if it's in 'x' case?!
@strager_
@strager_ Жыл бұрын
> 1:30:15, D.R.Y. assassination? I wouldn't say "assassination". It's not that bad, really. But yes, the copy paste should be fixed. > 1:38:14, does deleting 'x' content is the same as 2 identical blocks? Will it execute 'X' if it's in 'x' case?! Yes. C++ has case fallthrough by default.
@MrAbrazildo
@MrAbrazildo Жыл бұрын
​@@strager_ I thought fallthrough would still check the case for 'X'. And shouldn't you use the [[fallthrough]] (C++17)?
@strager_
@strager_ Жыл бұрын
> I thought fallthrough would still check the case for 'X'. Nope. That doesn't make sense, because only one case can equal the switch's input. > And shouldn't you use the [[fallthrough]] (C++17)? [[fallthrough]] is unnecessary if cases are right next to each other.
@DM-qm5sc
@DM-qm5sc Жыл бұрын
Computer Jesus! I found you!!!
@tricky778
@tricky778 11 ай бұрын
You don't need to write util:: everywhere, you just need using directives. But if your utils are not imported/shared/common/conflicting, then you don't need to bother.
@isodoubIet
@isodoubIet Жыл бұрын
The naming convention I personally favor in C++ is snake_case for everything that's not a type and Snake_case for types. This way I get the readability of snake_case with the benefits of distinguishing types from other things, like getting to use the very common pattern Foo = foo();. I hold to this even if the name contains acronyms; so a frobnicator for UTF-8 characters would be called a Utf_8_frobnicator. This avoids having to come up with unnatural names to prevent any class names ending up in ALL_CAPS, which to me looks like a macro.
@strager_
@strager_ Жыл бұрын
Hmm, this makes sense. I might try it some day.
@fano72
@fano72 11 ай бұрын
I prefer camel case, maybe because I am a Java nerd... Hate the underscores.
@guyross1664
@guyross1664 Жыл бұрын
2:20 you've come such a long way "I disagree with Zifre. Any repeated license at the top is irritating for me. - strager May 10, 2009 at 19:55"
@strager_
@strager_ Жыл бұрын
What.
@guyross1664
@guyross1664 Жыл бұрын
You wrote "Any repeated license at the top is irritating for me." May 10th, 2009. I was making a joke.
@ArriEllieJelly
@ArriEllieJelly Жыл бұрын
Holy hell
@felipecheung6826
@felipecheung6826 Жыл бұрын
how do you use Java
@strager_
@strager_ Жыл бұрын
I rarely deal with Java. I haven't written even 10k lines of Java, let alone 100k lines. So I think a Java video wouldn't be insightful. xD I do like IntelliJ for Java though.
@l.vanhielf6174
@l.vanhielf6174 Жыл бұрын
​@@strager_ IntelliJ is god
@aslkdjfzxcv9779
@aslkdjfzxcv9779 Жыл бұрын
dig the shirt
@sourestcake
@sourestcake Жыл бұрын
1:18:30 This is why i always use my own prefixed name for some questionably portable functions. So if i have to work around it, i don't have to go replace the name everywhere.
@strager_
@strager_ Жыл бұрын
For me, the problem isn't changing the codebase to use the new function. The problem is remembering to use my version in 6 months when I forgot I had to work around the bug. 🙈
@sourestcake
@sourestcake Жыл бұрын
@@strager_ One problem i have with code is that useless and outdated things don't look out of place at a glance. Sometimes i honestly leave snippets of code around because i quickly needed to go solve another problem and forgot to continue the previous one.
@cicerothecrow6958
@cicerothecrow6958 Жыл бұрын
Your code will run faster if you reduce the font size...... j/k. Thanks for sharing.
@strager_
@strager_ Жыл бұрын
My code would be so fast I can't even see it!
@allNicksAlreadyTaken
@allNicksAlreadyTaken Жыл бұрын
37:25 If I feel tempted to nest ternary operators, I turn it into an immediately invoked lambda instead. Honestly also in a significant part because clang-format poops its pants consistently otherwise, as you have demonstrated.
@strager_
@strager_ Жыл бұрын
Hmm, I don't know how I feel about it. I think immediately invoked lambda expressions are kind of ugly in C++, and that outweighs the ugliness of the conditional operators. What do you think? github.com/quick-lint/quick-lint-js/commit/463ca5ee1d4093221a0718ea0ebb9190041a5840
@isodoubIet
@isodoubIet Жыл бұрын
@@strager_ One thing you can do when clangformat craps its pants is to use empty // to add newlines in the appropriate places. It's ugly still, but better than bad formatting, and way better than /* clang-format off */ nonsense. I found most instances of bad formatting could be turned into something acceptable with this (not sure there's much it can help re nested ternaries though)
@user-zl8il5ki8e
@user-zl8il5ki8e Жыл бұрын
friendly to newbie
Faster than Rust and C++: the PERFECT hash table
33:52
strager
Рет қаралды 532 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 241 М.
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 10 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 11 МЛН
Best KFC Homemade For My Son #cooking #shorts
00:58
BANKII
Рет қаралды 72 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН
How to contribute to open source
14:15
strager
Рет қаралды 103 М.
Bevy: A quick introduction
7:20
Isaac Corbrey
Рет қаралды 7 М.
Big O myths busted! (Time complexity is complicated)
21:33
strager
Рет қаралды 133 М.
So, you want to be a programmer?
20:43
ForrestKnight
Рет қаралды 243 М.
The Downsides Of C++ | Prime Reacts
21:23
ThePrimeTime
Рет қаралды 131 М.
Real-Time Air Traffic Control Game! // Code Review
36:50
The Cherno
Рет қаралды 56 М.
Programming Languages I used at Google (C++ rant)
6:14
NeetCodeIO
Рет қаралды 71 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2 МЛН
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 385 М.
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 148 М.
Проверил, как вам?
0:58
Коннор
Рет қаралды 337 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18