The same way Javascript is becoming more and more declarative and functional in style, I hope the same thing happens in C++.
@MrAbrazildo Жыл бұрын
7:00, my father writes: status=1, with no spaces. Prone to error, in my opinion. 8:40, I like that: it leads to fast typing, faster production speed. 11:20, even if they only thought about compression, the result was quite good. For those who don't approve it, there's always the macro possibility: #define atrib = #define equal == 11:54, I love compact code. I'm often writing macros to smash code - when it doesn't lead to loss of speed, of course . 12:09, and should be. Amen. 15:12, this is something I wanted more than 10 years before C++17. I used to emulate that with: for (auto sp = wp.lock(); sp; ) { b = sp->bar(); break; } And got frustrated for not being allowed to put break as the 3rd for parameter (to get rid of the { }). 16:00, is this well defined behaviour? If lock() returns a nullptr, is there any chance compiler would 1st execute wp.lock()->bar()? About the double lock, isn't compiler smart enough to avoid that?
@jhbonarius4 жыл бұрын
Great talk... but I would really like more examples to grasp the subjects..
About assignment, instead of calling the lambda, one can pass it to std::invoke - this way it will be more what the statement does.
@krytharn6 жыл бұрын
Ten minutes in and I still don't know what is meant by "declarative style". On top of that, I now find myself puzzled by what "yoda conditions" are.
@skellyjell6 жыл бұрын
"Saying what you want to happen, not how it's done"
@brenogi6 жыл бұрын
Yoda conditions is to write: if (0 == val) ... ; That was useful because if you forget to add one "=", you get if (0 = val), which will not compile.
@theskett6 жыл бұрын
@@brenogi - thank you, I was aware of the benefit ("lvalue required as left operand of assignment" etc.) but not of the handy Yoda mnemonic :-)
@steveragnar11556 жыл бұрын
So give a more concrete example of the utility of std::identity - please
@quincunx27186 жыл бұрын
A good example is Ranges in C++20. The range algorithms have a projection parameter, so that you can write the following to find the first string of size 6: std::ranges::find(my_strings, 6, [](const std::string& s) { return s.size(); }) If you don't want a projection, std::identity does what you want, and in fact, the projection parameter is defaulted to std::identity: std::ranges::find(my_strings, "meow"sv, std::identity) // equivalent to: std::ranges::find(my_strings, "meow"sv)
@steveragnar11556 жыл бұрын
@@quincunx2718 This is not a good example. First of it's requiring knowledge of C++20, ranges, and 2nd, what on earth is a 'projection' and a projection parameter? The whole point of the talk was about a 'declarative' style of writing modern C++ code - tomorrows production code using C++17: the presenter threw in std::indentity as a component to achieve a 'declarative' style. Your example introduces a non-standard language facilty and a new concept of 'projection'. Yes. I've had to look it 'projection' in the context of ranges and my first reaction is 'eh'? It seems a poor word for what it seems to do or conceptualise. I'm still not clear. How is your example 'declarative'?
@JonathanSharman6 жыл бұрын
@@steveragnar1155 "Projection" is not a new concept; it's a common term for a very common (relational algebra) operation. I would expect anyone who's ever written database queries to understand projection. And even though ranges isn't standard yet, it's a popular third party library and will be standard in a couple years. His example is declarative because it expresses what the programmer wants (the first length-6 substring) without saying how to compute it.
@steveragnar11556 жыл бұрын
@@JonathanSharman LOL! Your expectations are unrealistic!
@LemonChieff5 жыл бұрын
I try to use {} as much as I can but I'm so used to type `int num = 0;` that it's hard for me to type `int num{0};` I try to tho.
@YourCRTube5 жыл бұрын
He was talking about assignment, not initialization.
@MrAbrazildo Жыл бұрын
The idea is: if you can compute all possible values for num, right at its declaration, you can make it const, for the rest of its lifetime. Usually, it'll require an expression between { }. It's not the same thing as calling a f(), because the entire project will be allowed to do that too, by mistake. And even if num won't ever be const, it's still better to compute its initial value at its declaration, because: a) it's 1 "single" command (you can think it this way), even when a whole { } expression is embracing it; b) It's harder to forget to attribute its value, if all is done right away; c) I guess you make compiler's life easier, by not annoying it with things you won't be using immediately - I guess I heard somewhere else it's easier for it to optimize the code too.
@arnebovarne77594 жыл бұрын
One loses the point when one uses rather special examples. Examples that are rarely relevant to most people. Examples should be relevant, but not "toy problems". Many people stop watching the video during this example I think. (14:00-19:00)
@MrAbrazildo Жыл бұрын
If you hold the expression, you can think it as "the value for b". While if it was a free code, you would be looking for each statement, think "What it is doing here?", and building the picture in your head, to finally realizing: "this block computes the value for b".
@davidjohnston42402 жыл бұрын
Making simple things complicated for fun and profit.
@MrAbrazildo Жыл бұрын
It takes more initial work and can look intimidating, but compensates soon. If you followed all the SFINAE history, you can see that it made templates a lot safer.
@morglod2 жыл бұрын
Making simple things more and more complicated instead of just stop writing shitcode
@MrAbrazildo Жыл бұрын
It takes more initial work and can look intimidating, but compensates soon. If you followed all the SFINAE history, you can see that it made templates a lot safer.