CppCon 2018: Ben Deane “Easy to Use, Hard to Misuse: Declarative Style in C++”

preview_player
Показать описание


We say that interfaces should be easy to use and hard to misuse. But how do we get there? In this talk I will demonstrate how using declarative techniques in APIs, functions, and plain old “regular” code can help.

We’ll look at what is meant by “declarative style” in C++; explore why declarative interfaces are desirable and how to construct them; and take an in-depth look at which features of C++ help us write in a declarative style.

I want to deconstruct C++ a bit, examine what we’re doing and what makes the good parts good, and from that reconstruct some best practices. Many of us are already writing code following piecemeal modern advice such as “no raw loops”, or “almost always auto”, or C++ core guideline recommendations. In many cases, this advice translates to writing more declarative code; being deliberate about exploring and using declarative techniques gives us insight we can apply more widely.

Ben Deane
Ben was in the game industry for 23 years, at companies like EA and Blizzard. He's always looking for useful new techniques in C++, and he | geeks out on algorithms, APIs, types and functional programming.


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

The same way Javascript is becoming more and more declarative and functional in style, I hope the same thing happens in C++.

Max-wkcg
Автор

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?

MrAbrazildo
Автор

Great talk... but I would really like more examples to grasp the subjects..

jhbonarius
Автор

About assignment, instead of calling the lambda, one can pass it to std::invoke - this way it will be more what the statement does.

YourCRTube
Автор

26:49 - "R Tape Loading Error" nice easter egg for ZX Spectrum users

vividbw
Автор

So give a more concrete example of the utility of std::identity - please

steveragnar
Автор

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.

krytharn
Автор

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.

LemonChieff
Автор

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)

arnebovarne
Автор

Making simple things complicated for fun and profit.

davidjohnston
Автор

Making simple things more and more complicated instead of just stop writing shitcode

morglod