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

Sdílet
Vložit
  • čas přidán 27. 12. 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
    CZcams Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
    ---
    Registration for CppCon: cppcon.org/registration/
    #cppcon #cppprogramming #cpp
  • Věda a technologie

Komentáře • 49

  • @johnwellbelove148
    @johnwellbelove148 Před 4 měsíci +14

    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).

  • @nicolabombace2004
    @nicolabombace2004 Před 3 měsíci +2

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

  • @kacperkrol4394
    @kacperkrol4394 Před 4 měsíci +1

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

  • @Quarky_
    @Quarky_ Před 4 měsíci +15

    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 Před 4 měsíci +10

      itCppCon20 - My Least Favorite Anti-Pattern (Conor Hoekstra)
      czcams.com/video/CjHgL5EQdcY/video.html
      CppCon 2019: Conor Hoekstra “Algorithm Intuition (part 1 of 2)”
      czcams.com/video/pUEnO6SvAMo/video.html
      CppCon 2019: Conor Hoekstra, “Algorithm Intuition (part 2 of 2)”
      czcams.com/video/sEvYmb3eKsw/video.html
      CppCon 2016: Ben Deane "std::accumulate: Exploring an Algorithmic Empire"
      czcams.com/video/B6twozNPUoA/video.html
      CppCon 2018: Jonathan Boccara “105 STL Algorithms in Less Than an Hour”
      czcams.com/video/2olsGf6JIkU/video.html
      C++ Seasoning was already posted in the comments

  • @WhiteEyeTree
    @WhiteEyeTree Před 4 měsíci +4

    @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 Před 3 měsíci +2

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

  • @oddprhyme
    @oddprhyme Před 4 měsíci +1

    well prepared talk. good job and thank you!

  • @VoidloniXaarii
    @VoidloniXaarii Před 4 měsíci +4

    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

  • @RonanMevel
    @RonanMevel Před 4 měsíci +1

    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 !

  • @fbjerno1
    @fbjerno1 Před 4 měsíci +5

    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 Před 4 měsíci +3

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

  • @multiHappyHacker
    @multiHappyHacker Před 4 měsíci +3

    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.

  • @spacelem
    @spacelem Před 4 měsíci +2

    As a mathematical modeller, most of my code looks like
    while (t < T) { /* lots of complex code with many layers of loops */ }
    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).

  • @John-xl5bx
    @John-xl5bx Před 4 měsíci +2

    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....

  • @hwval-zw4hy
    @hwval-zw4hy Před 4 měsíci +1

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

  • @nigelstewart9982
    @nigelstewart9982 Před 4 měsíci +1

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

  • @SimonToth83
    @SimonToth83 Před 4 měsíci +1

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

  • @sprytnychomik
    @sprytnychomik Před 3 měsíci +1

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

  • @multiHappyHacker
    @multiHappyHacker Před 4 měsíci +2

    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 Před 4 měsíci +1

      The projection can be a lambda function so yes.

  • @Roibarkan
    @Roibarkan Před 4 měsíci +6

    C++ Seasoning, Sean Parent, GoingNative 2013: czcams.com/video/qH6sSOr-yk8/video.html

  • @steelpanther88
    @steelpanther88 Před 4 měsíci +1

    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 ?

  • @ulysses4536
    @ulysses4536 Před 4 měsíci +1

    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

  • @christer8964
    @christer8964 Před 3 měsíci +1

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

    • @coarse_snad
      @coarse_snad Před 3 měsíci

      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.

  • @cranil
    @cranil Před 4 měsíci +1

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

  • @The1RandomFool
    @The1RandomFool Před 4 měsíci

    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
    @JansthcirlU Před 4 měsíci +1

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

  • @KX36
    @KX36 Před 4 měsíci +1

    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
    @sciptick Před 4 měsíci +1

    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 Před 4 měsíci +1

      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
    @stefanplusplus917 Před 4 měsíci +2

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

  • @Key_Capz_
    @Key_Capz_ Před 4 měsíci

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

  • @lidegao
    @lidegao Před 4 měsíci

    love the simpsons

  • @ElPikacupacabra
    @ElPikacupacabra Před 4 měsíci +18

    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 Před 4 měsíci

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

    • @mcpr5971
      @mcpr5971 Před 4 měsíci +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 Před 4 měsíci

      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 Před 4 měsíci

      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 Před 4 měsíci +7

      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
    @u28OO Před 4 měsíci

    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 Před 4 měsíci +2

      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 Před 3 měsíci

      🤡

    • @n00blamer
      @n00blamer Před 2 měsíci

      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.