Back to Basics: (Range) Algorithms in C++ - Klaus Iglberger - CppCon 2023

Ғылым және технология

cppcon.org/
---
Back to Basics: (Range) Algorithms in C++ - Klaus Iglberger - CppCon 2023
github.com/CppCon/CppCon2023
“There was never any question that the [standard template] library represented a breakthrough in efficient and extensible design” (Scott Meyers, Effective STL, 2008)
Originally developed as part of the Standard Template Library (STL), algorithms have become a must-know tool for every C++ developer. They increase productivity, significantly reduce bugs, and improve maintainability. This talk explains why and how algorithms do this. Additionally, it demonstrates why they are an amazing example for good, extensible software design.
---
Klaus Iglberger
Klaus Iglberger is a freelance C++ trainer and consultant. He has finished his PhD in Computer Science in 2010 and since then is focused on large-scale C++ software design. He shares his expertise in popular advanced C++ courses around the world (mainly in Germany, but also in the rest of the EU and the US). Additionally, he is the author of “C++ Software Design”, the initiator and lead designer of the Blaze C++ math library, one of the organizers of the Munich C++ user group, and the (co-)organizer of the Back-to-Basics and Software Design tracks at CppCon.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZread Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---
Registration for CppCon: cppcon.org/registration/
#cppcon #cppprogramming #cpp

Пікірлер: 49

  • @johnwellbelove148
    @johnwellbelove1485 ай бұрын

    I remember many years ago (when I was getting to grips with C++) coming across the algorithms. I applied them to our codebase and the reduction in the amount of code, and improvement in readability was astounding at the time. And what's more, no reduction in performance (the application was for real-time image analysis).

  • @Quarky_
    @Quarky_5 ай бұрын

    Great talk! I'm halfway through, the examples are simple to follow, gives practical steps, compares different standards, and the icing on the cake is referencing previous talks for more details! Maybe someone can update the video description with links to these "further watching" talks?

  • @dimodimi

    @dimodimi

    5 ай бұрын

    itCppCon20 - My Least Favorite Anti-Pattern (Conor Hoekstra) kzread.info/dash/bejne/dZ58ya5udbTKk7w.html CppCon 2019: Conor Hoekstra “Algorithm Intuition (part 1 of 2)” kzread.info/dash/bejne/ool50LFvg9mnfdI.html CppCon 2019: Conor Hoekstra, “Algorithm Intuition (part 2 of 2)” kzread.info/dash/bejne/pXmqu8-bY8ixo9o.html CppCon 2016: Ben Deane "std::accumulate: Exploring an Algorithmic Empire" kzread.info/dash/bejne/dGqo2dGzfrO7n6Q.html CppCon 2018: Jonathan Boccara “105 STL Algorithms in Less Than an Hour” kzread.info/dash/bejne/ZKOg1amfZq2vm7g.html C++ Seasoning was already posted in the comments

  • @nicolabombace2004
    @nicolabombace20044 ай бұрын

    Klaus' conference talk? Like before watching! EDIT: Finished the talk, I wish there was a double like button! :D

  • @kacperkrol4394
    @kacperkrol43944 ай бұрын

    Have to admit that Klaus i in my opinion the best lecturer in CppCon! Thanks for speech ;)

  • @VoidloniXaarii
    @VoidloniXaarii5 ай бұрын

    Thank you for this both great and entertaining even at times amusing talk! So much to learn... Makes great teachers of deep knowledge rather priceless... Thank you

  • @WhiteEyeTree
    @WhiteEyeTree5 ай бұрын

    @27:12 Instead of using rotate you could just partition for the negation of what you want in the end, everything that is not what you want in the end gets put in front of it. It also maintain the relative order. Just a thought.

  • @nicolabombace2004

    @nicolabombace2004

    4 ай бұрын

    This is actually addressed @54:25. It was an inside joke to mention rotate

  • @RonanMevel
    @RonanMevel5 ай бұрын

    Great talk, thank you !I've always ket in my mind the talk from Sean Parent you've mentionned and his advise : Know your STL !

  • @oddprhyme
    @oddprhyme5 ай бұрын

    well prepared talk. good job and thank you!

  • @fbjerno1
    @fbjerno15 ай бұрын

    I think in practice the time it takes to read the raw code in many of these examples is shorter than the time it takes to look up the algorithm function on cppreference. Using indexing and size() instead of begin()/end() would in my opinion be way clearer, especially for people who program in languages other than C++.

  • @nigelstewart9982

    @nigelstewart9982

    5 ай бұрын

    C++ containers do not necessarily support random access for indexing, or even know their own size. That's the generality of iterators.

  • @multiHappyHacker
    @multiHappyHacker5 ай бұрын

    I suspect that using an operator overload to make Person less-than-comparable would be making your code depend on the algorithm code instead of the other way around.

  • @John-xl5bx
    @John-xl5bx5 ай бұрын

    On one hand this is great - there is a more elegant way to do these things. On the other hand, we now have yet one more substantially different way to do basic things. Even "using the STL algorithm" now includes several alternate approaches. This worsens the C++ code readability nightmare. The technical debt compounds....

  • @StanleyPinchak

    @StanleyPinchak

    4 ай бұрын

    Unmaintainable for loops for teh win!

  • @nigelstewart9982
    @nigelstewart99825 ай бұрын

    Nice one Klaus. I was thinking of making a trip to the USA this year, perhaps CppCon 2024 is as good excuse as any?

  • @spacelem
    @spacelem5 ай бұрын

    As a mathematical modeller, most of my code looks like while (t Trying to remove the main loop feels like a gargantuan task, however I do like to use algorithms wherever it makes life easier (which probably isn't the main loop).

  • @sprytnychomik
    @sprytnychomik4 ай бұрын

    That int in accumulate doubles situation shows how type-safe C++ really is. Not even a warning [from a compiler].

  • @SimonToth83
    @SimonToth835 ай бұрын

    @44:00 Definitely worth mentioning that the result is now non-deterministic (which can be totally fine).

  • @hwval-zw4hy
    @hwval-zw4hy5 ай бұрын

    1. C++ seasoning 2. 105 STL algorithms in less than an hour 3. Algorithm intuition

  • @Roibarkan
    @Roibarkan5 ай бұрын

    C++ Seasoning, Sean Parent, GoingNative 2013: kzread.info/dash/bejne/o3xq1bWIopDfm5s.html

  • @letsbegin_staytrue

    @letsbegin_staytrue

    5 ай бұрын

    Thanks !!

  • @multiHappyHacker
    @multiHappyHacker5 ай бұрын

    Also, is it possible to use the projection-based form of min_element when you have a struct composed of 3 more structs? (and the element you are looking for is a sub-element of one of those inner structs)

  • @randfur

    @randfur

    5 ай бұрын

    The projection can be a lambda function so yes.

  • @steelpanther88
    @steelpanther885 ай бұрын

    This is quite nice this ranges stuff... Well, at least we can do our own projects with c++ 20. The joys of working with legacy code😔 Btw is this ranges included in g++ 12.3.0 ?

  • @christer8964
    @christer89644 ай бұрын

    @27:26 Shouldn't pos be pos.begin()?

  • @coarse_snad

    @coarse_snad

    3 ай бұрын

    I think it's because 'pos' is an iterator. The '.begin()' method on containers is used to get the start iterator from them, but 'pos' is already an iterator here.

  • @ulysses4536
    @ulysses45365 ай бұрын

    Yeah, one should really learn to appreciate the STL. And the fact that it's free. I love ranges, even though many useful things are only added in v23. It's still a very helpful thing in 20 as you present

  • @cranil
    @cranil5 ай бұрын

    Only problem with the talk is Bart would never be this nice to Lisa 😂

  • @The1RandomFool
    @The1RandomFool5 ай бұрын

    Isn't a successful exit of the program supposed to require returning 0? It seems odd to me that someone would make a macro named EXIT_SUCCESS just for 0. At least in Fish, it will print the exit code of the program to the terminal if the exit code is not 0.

  • @JansthcirlU
    @JansthcirlU5 ай бұрын

    The absolute irony of doing a whole talk about single-dimensional ranges and naming the main variable for all of your examples 'table'

  • @KX36
    @KX365 ай бұрын

    what if the bart simpsons i know only use C arrays, raw loops and pointer arithmetic and cast every pointer to a void* because they religiously believe it performs better but they refuse to piss off and get C jobs.

  • @sciptick
    @sciptick5 ай бұрын

    Listing "Containers" as primary to the STL is extremely weird. The most essential part of the STL was always the iterators. After that, the algorithms. The containers were meant mainly as examples. Stepanov's expectation was that people would routinely make up their own containers; it was quite a surprise that the initial containers proved adequate for so much development, and have been added to so very slowly. His hope was that the list of algorithms would be added to by many, continually. That hope was disappointed. The whole library was meant as a way to make important algorithm implementations universally usable, and thus amortize work on optimizing testing, and proving them over widespread use. Fun fact, priority_queue got in only because Stepanov thought the committee would cut the library down, so priority_queue and for_each were "sacrificial", added to save stack, queue, and accumulate from being cut. He was astonished when the committee took it all as-is. It is why priority_queue needed so much repair, after.

  • @mcpr5971

    @mcpr5971

    5 ай бұрын

    people writing their own containers instead of getting things done is extremely weird. You really think we're supposed to re-invent map and vector? lol okay...

  • @stefanplusplus917
    @stefanplusplus9175 ай бұрын

    the simpsons made this amazing talk 10x better. or maybe they made it amazing in the first place😜

  • @lidegao
    @lidegao5 ай бұрын

    love the simpsons

  • @Key_Capz_
    @Key_Capz_5 ай бұрын

    well, since you put it that way, it makes more sense.

  • @ElPikacupacabra
    @ElPikacupacabra5 ай бұрын

    I'm gonna to keep it real with you chief. I prefer to do for loops. 😐 I would rather memorize a few useful algorithms than C++ syntax and a grab-bag of function names. If I know the algorithms, I will be able to use them forever, in any programming language.

  • @ukissrulez

    @ukissrulez

    5 ай бұрын

    You overestimate yourself. You are a nobody watching youtube videos.

  • @mcpr5971

    @mcpr5971

    5 ай бұрын

    that's fine, and without knowing it you're wasting your own time writing and re-writing algorithms that have already been written, optimized and debugged. If you prefer to sit in the warm kiddie pool that is safe, familiar, and full of urine, that's always your choice. But there's way more out there for people who have ambition.

  • @colinjohnson5515

    @colinjohnson5515

    5 ай бұрын

    The other thing I’ve noticed as a cpp newb is how many helper funcs are C++20 which is a letdown after searching for std lib tools in languages like C#, Go, JS and Python.

  • @alirezanikpay

    @alirezanikpay

    5 ай бұрын

    Sure, you should know the algorithms, but you should use the proper library in your language to use them. It's like I should know how to cut a tree with axe, but I prefer chainsaw if it's available.

  • @not_ever

    @not_ever

    5 ай бұрын

    I’m gonna keep it real with you. I don’t want to work with you or any code you’ve worked on. I prefer code to be readable and not contain bugs. I don’t want to reason through your, or anyone else’s, hand rolled version of an stl algorithm I already know or can recognise at a glance and look up on cpp reference. Yes you should know how algorithms work under the hood and be able to implement them if necessary but writing idiomatic code is important in all programming languages and C++ is not an exception to this rule.

  • @u28OO
    @u28OO5 ай бұрын

    C++ SUCKS!!! It's slow as hell!! I always have to go back to C functions for a 4x performance boost!1;1!!1

  • @nigelstewart9982

    @nigelstewart9982

    5 ай бұрын

    You may have overlooked the fact that the compiled for loop compiled to the same assembly as the C++ algorithm. No way that is a 4x performance boost.

  • @StanleyPinchak

    @StanleyPinchak

    4 ай бұрын

    🤡

  • @n00blamer

    @n00blamer

    3 ай бұрын

    Obvious bait, but fuck it, I am a troll too: copy paste your C code into cpp file and compile it with a C++ compiler. PWN3D.

Келесі