Down the Rabbit Hole: An Exploration of Stack Overflow Questions - Marshall Clow - CppCon 2021

preview_player
Показать описание
---
This is the Closing Keynote of the Back to Basics Track.

Many Stack Overflow questions are straightforward - "How do I do sort a vector in decreasing order?" for example. But some of them are subtle, and the more you look at them, the more different possible answers appear.

In this talk, I will show a few SO posts, and discuss possible solutions. These will involve tradeoffs between different data structures and algorithms, complexity guarantees, algorithm design, performance measurement, and testing alternatives.

This talk requires moderate familiarity with the standard library and the contents of the STL.

---
Marshall Clow

---

*--*
Рекомендации по теме
Комментарии
Автор

A major reason people describe the "rabbit hole" they're in is Stack Overflow closes questions without sufficient effort behind them, and people downvote any question like that as well.

AG-ldrv
Автор

18:40 - and that's why I'm in love with Computer Science for the past three decades...

ecosta
Автор

Really interesting concept for a talk!
I would gladly watch a whole YouTube series riffing on this idea :)

superscatboy
Автор

Funny, seeing the "better than nth_element" solution to the first problem with the "first_two" algorithm: that's how somebody that doesn't know the std algorithms would likely solve it. So "know your algorithms" is not only "know they exist" but also "know their weaknesses", because they're not always the best solution?

jhbonarius
Автор

Second problem: I would definitely use an explicit cast to unsigned char. And write a specific test for this. Else some developer after me could "auto everything" during some upgrade refactoring and break the code.

jhbonarius
Автор

For the 2nd problem, I am really confused why the following approach works (my own walk-around but was not covered in this talk):

Add "using namespace std;" and use ::ispunct instead of ispunt. Then the code will compile and run as expected. Please note that neither std::ispunct nor ispunct (without a scope ::) would work. Only ::ispunct works. What really confuses me is that given that I already added "using namespace std", what's the difference between ::ispunct and std::ispunct (or ispunct without a scope)?

pengliu
Автор

It's not surprising that nth_element does a lot more work.
It loosely sorts the entire sequence because it matters what's left and right of the nth element.
Partial sort does not have that overhead since it only moves a few elements to the beginning after a linear iteration

fob
Автор

46:28 - I may be wrong about this, but I'm pretty sure you can pass _any_ char value to ispunct and it will always work. UB comes if you pass it values like 512, which cannot be converted to an unsigned char. If your platforms characters are signed, -5 can still be converted to an unsigned character, and it will usually (8 bit char, two's complement representation) get you the value 251.

Omnifarious