CppCon 2015: Andrei Alexandrescu “Declarative Control Flow"
Вставка
- Опубліковано 26 сер 2024
- www.Cppcon.org
-
Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/cpp...
-
Getting exception handling right is a perennial problem in C++ that has eluded systematization. Not for much longer. New language and library developments make it possible to handle exceptions in a declarative manner, leading to drastic code simplification.
This talk discusses an alternative approach to handling exceptional flow that eliminates the need for small ancillary RAII classes, try/catch statements that rethrow, and other cleanup mechanisms. The popular Scope Guard idiom gets a spectacular generalization. Statements specify in a declarative manner actions to be taken if the current scope is left normally or via an exception. The resulting code is simpler, smaller, and easier to maintain.
-
Andrei Alexandrescu is a researcher, software engineer, and author. He wrote three best-selling books on programming (Modern C++ Design, C++ Coding Standards, and The D Programming Language) and numerous articles and papers on wide-ranging topics from programming to language design to Machine Learning to Natural Language Processing. Andrei holds a PhD in Computer Science from the University of Washington and a BSc in Electrical Engineering from University "Politehnica" Bucharest. He works as a Research Scientist for Facebook.Website: erdani.comTwitter handle: @incomputable
-
Videos Filmed & Edited by Bash Films: www.BashFilms.com
*-----*
Register Now For CppCon 2022: cppcon.org/reg...
*-----*
All of Andrei's talks are really informative, but he makes them entertaining and enjoyable. Great presenter.
This guy is so enjoyable to watch!
"Picture this: Imagining like its 1960, this is a guy at conference, he said, you know there is the global variable and it was good." -epic
This is one of the most entertaining and interesting talks Andrei has given, in my opinion. The techniques made for code that was logically clear, as well as subjectively very clean. He was also on fire in terms of his jokes too, which kept me engaged the whole way through. Great work!
Also, nicely edited! Some of these CppCon 2015 videos were pretty rough, but this was clean and tidy.
"It works better if it is turned on."
I almost had my coffee coming out of my nose.
This is actually a presentation on banter flow
It just gets better every time I watch it!
That guy is brilliant.
He is the Chuck Norris of C++ Programming
yes, and even is one of the inventors of another language
A great presenter and an interesting subject.
His jokes are the best.
I said no refunds 😅😂
The gcc-5.2 I have on my Debian system doesn't have std::uncaught_exceptions, but I just used std::uncaught_exception (bool) for now, and I'll change it soon(?) when the support comes. This gives a nice simplification of code when it's applicable.
Finishing presentations at the last minute... Been there.
What I wanted to imply is that CL and C++ are targeted at completely different segments. We use Scala at work, and there is a library to do scoped cleanup, because Scala is quite flexible. However, we totally miss the ability to do clean ups automatically based on scope. Just because a language offers some meta-programming capability in a fashion that's easier than C++, does not mean it's strictly superior. Furthermore, at the end of the day, this ability is mainly used by library writers [tbc]
There isn't any meta-programming here. It's simply the RAII + lambdas + the new uncaught_exceptions() to check for normal / exceptional exit from scope, with a bit a preprocessor macros to reduce typing.
🤗thank you Andrei 🤗
nice anonymous variable trick at 22:44
This guy is absolutely hilarious!
Can someone recommend some beginner-intermediate talks on this channel? Because this is too complicated for me as an early intermediate
FYI: `static_if` is not slated for C++17... yet. The committee essentially decided to go the concepts route, but there is a variation of `static_if` called `constexpr_if` that could yet make it to C++17.
it did xD
But if copy file fails no file gets copied and then the deletion night succeed which would mean files are gone right?
Yeah, but copy throws, if something goes wrong and then exits the function before any cleanup will be done.
Why would using SCOPE_* macros in an inline function ever violate the one definition rule? I can see why using them in macros might, but inline functions get their own scope. There should be no issue there.
It's not about the scope of the function, the function itself can have multiple definitions (in more than one translation unit), which often happens to inline functions, e.g. when defined in the class header. Using __COUNTER__ in this case can obviously lead to ODR violation.
I think this could be fixed using some sort of scope-sensitive __COUNTER__ or simply a macro for local object naming, which could be implemented easily by the compiler, so no reason for Chandler to be such a cockblocker:)
For an example of code being executed automatically on certain events, look at the Kenny Tilton's Cells library.
With it you can create objects where the values of members depend on the values of the members of other objects. When you update one member variable, the values of all dependent members, including in other objects, get updated recursively.
Will RAII enable you to write such code?
He's a good presenter, but I fell off the wagon when he started with the macros.
and consumed by application writers, so only relatively few people would need to know all the intricacies of this. With C++14 and C++17, metaprogramming abilities are becoming easier to use by the non-specialists too (see static_assert and static_if for instance).
I also invite you to check out Rust, it has decent metaprograming capabilities (and planned to get better in the future). For instance, they already have a compile time regex verifier -- if your regex has a bug [tbc]
Ziad Hatahet To problem with rust is it’s very awkward syntax at least sometimes. Also don’t like cargo wich is what i need for pretty much anything. Also would probably put all in unsafe { } because i want to use raw pointers without this stupid ownership model.
Room full of computer geeks and there's an issue with the slideshow. Classic.
First of all, your question isn't really related to what I said, which is that it is a torture to use C++ for meta-programming. Object lifetime management has little to do with syntactic abstractions.
But to answer your question - not but so what? For scoped cleanup, which is a great portion of the uses of RAII, it has unwind-protect. For the rest (subordinate objects) there are alternatives.
Last but not least, CL's meta-programming is so powerful, you could embed a RAII DSL in it.
Id name it on_next_scope_fail but that's because im new to code
You should definitely look at D ;)
This approach makes a good spaghetti of the code. Good luck debugging that mishmash.
Right? 18:25 - "What does this guy do?" It creates bugs, because no one understands it.
HebaruSan it's pretty straightforward 😅
How can you guys not understand #SCOPEFAIL{ do shit } Bah... Get off my lawn you kids lol, straight up spoiled by modern C++ don't know shit about real programming.
23:45 watch later
32:04
@@yash1152
I hate macros too.
I don't like typing the same thing over and over....
... the program will fail to compile. Quite awesome.
Look, I'm not saying lisp is superior in every respect. There are things in it I don't like.
But this presentation involves meta-programming, and what I'm saying is that C++ is extremely bad at this. To really appreciate how bad, you should compare it to the best meta-programming language, and that's lisp. Until you know what's possible (and easy), you can't really see how much C++ is missing in this area.
BTW, Andrei is great as usual, but he's forced to use a very bad tool for the task.
ok
If you think this is cool, you should read "On Lisp" and "Let Over Lambda". There's much cooler stuff than this before page 40. And by the end of these books you'll have seen so many cool constructs that will never be possible in C++, and done so effortlessly , you'll never admire any "meta" programming in C++ ever again.
lisp is elegant but you pay in runtime cost
I am not sure about what you mean by "runtime cost", but must say that 1) there are different implementations of lisp and 2) lisp can have compile time in runtime. This cost is somehow inevitable, just for C++ it is clearly separated from runtime. Also as far as I know in SBCL generated runtime is on par with C. For me the problem with lisp is in too steep ladder of abstraction.
walter0bz 99% of performance issues in the real world is because of shit code not because someone used lisp instead of cpp
Nah, its because noone uses lisp anyway, lol.
Andrei is boring as usual...
I gave up after five minutes of waffle and facetiousness. This is not the way to do a presentation.
Though I agree with the style-dismay, I watched it out. It was worth it.
You've got to suffer through the waffle, it's pretty good.
For me everything was perfect, including the humor. I bet it depends on culture: for me it is compatible, for you seems to be not.
"Waahhhhhh, wahhhhhhhh, waaaahhhhh...!" -Graham Asher, -2015
The introductory waffle and facetiousness (which I enjoyed and glad was recorded for posterity) ends and the material of the talk @6:00