CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"
CppCon2 HN recommenders · 2016–2022
102K views · talk · evergreen · Uploaded 2015-10-18
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.
Pointed to in threads on defer, scope_exit and RAII as the clearest treatment of scope guards.
1:12:27CppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
51:18Lexical Scanning in Go - Rob Pike
GoogleFOSSSydney
59:34CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
42:30RustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
1:19:52CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”
CppCon
1:55:24Ideas about a new programming language for games.
Jonathan Blow
1:27:46CppCon 2014: Mike Acton "Data-Oriented Design and C++"
CppCon
2:11:32How I program C
Eskil Steenberg
5 comments from Hacker News
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 gets very convoluted, and you don't want to deal with directly. See: Andrei Alexandrescu - Declarative Control Flow ( [VIDEO] )
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]
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] )
I think scope or similar is good. Also, see related video here CppCon 2015: Andrei Alexandrescu “Declarative Control Flow" [VIDEO]
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]