CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"
Channel:CppCon · Length:1:07:34 · Published:2015-10-18 · Views:102204
Summary
Andrei Alexandrescu's CppCon 2015 talk on handling exceptional control flow declaratively in C++. It uses scope guards with success and failure variants, built on std::uncaught_exceptions, to replace ad hoc RAII classes and rethrowing try/catch blocks.
Why HN recommends it
Pointed to in threads on defer, scope_exit and RAII as the clearest treatment of scope guards.
Andrei Alexandrescu has a fun talk about implementing scope_exit — HN, 2018
C, C++, Rust, Go & systems languages
Subtitles (excerpt)
it's a great honor to uh speak again at CBB conon um this is my second time after last year um I'm I've already seen a few familiar faces it's a great honor but also you got to imagine it's a great responsibility as well and there's like how many people in this room 200 I don't 400 no that would be so let's say 200 people and you're the best right I you're the best Folks at your respective organizations it's not like your employ went like oh Johnson is not doing his job he's drinking all the time under his desk not writing one of code let's send him to a conference no you're the best now you know is STL here because he says he's going to be here STL well I see Chandler there so Chandler's here imagine I play something like Inception on Chandler I plant a really bad idea in his mind he goes there and kind of spreads I mean here's the thing if I give you a bad day today the Astron folks in here I give you all a bad idea right now and this could have consequences on the history of humankind could could riple real bad right it could go like pretty consequential so um you know I mean picture this imagine like in 1960 there's this guy at the conference he said you know there's the global variable and it was good and then think of
On Hacker News
Andrei Alexandrescu has a fun talk about implementing scope_exit using a new C++17 function: std::uncaught_exceptions (which is a tweak to std::uncaught_exception). Fundamentally, it doesn't really solve the destructor throwing exceptions issue though. [VIDEO] — uep, 2018-02
Google is an example that writing production code that doesn't use exceptions is possible, not that this is the right thing to do. They said that their decision was primarily legacy-motivated (in short, they were fearing that introducing exceptions in a non-RAII codebase would lead us to a long period of instability). I'll add that in some situations (e.g when freeing resources) the control flow … — Ace17, 2016-07
A count of the number of exceptions in-flight was added, replacing the boolean indication of whether an exception is in-flight. This allows the scope guard construct proposed by Andrei Alexandrescu to distinguish between a scope being left on success and on an exception being thrown. YouTube video about scope guard: [VIDEO] Description of the change to the standard: [LINK] — einpoklum, 2022-10
I think scope or similar is good. Also, see related video here CppCon 2015: Andrei Alexandrescu “Declarative Control Flow" [VIDEO] — watmough, 2022-06
yes, you always run defer. I don't see it in this proposal, but Most languages/frameworks that implement a defer also implement a "error defer" which only gets triggered on some sort of labeled early exit scenario, and some implement "success defer": (i believe this is scopeguard: [VIDEO] ) — dnautics, 2020-12
Related videos
- CppCon 2015: Andrei Alexandrescu “std::allocator...” · CppCon · 1:12:27
- Lexical Scanning in Go - Rob Pike · GoogleFOSSSydney · 51:17
- CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step” · CppCon · 59:33
- RustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West · Rust Programming Language · 42:29
- CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17” · CppCon · 1:19:52
- Ideas about a new programming language for games. · Jonathan Blow · 1:55:24
- CppCon 2014: Mike Acton "Data-Oriented Design and C++" · CppCon · 1:27:46
- How I program C · Eskil Steenberg · 2:11:32
- Google I/O 2012 - Go Concurrency Patterns · Google for Developers · 51:27
- CppCon 2015: Kate Gregory “Stop Teaching C" · CppCon · 1:00:11
- Zig: A programming language designed for robustness, optimality, and clarity – Andrew Kelley · Recurse Center · 54:13
- CppCon 2014: Chandler Carruth "Efficiency with Algorithms, Performance with Data Structures" · CppCon · 1:13:41
- The Road to Zig 1.0 - Andrew Kelley · ChariotSolutions · 59:47
- CppCon 2019: Chandler Carruth “There Are No Zero-cost Abstractions” · CppCon · 59:52
- CppCon 2017: Juan Pedro Bolivar Puente “Postmodern immutable data structures” · CppCon · 1:05:59
- Casey Muratori | Smart-Pointers, RAII, ZII? Becoming an N+2 programmer · xDahl · 30:12