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...
    *-----*

КОМЕНТАРІ • 60

  • @jammehcow
    @jammehcow 6 років тому +59

    All of Andrei's talks are really informative, but he makes them entertaining and enjoyable. Great presenter.

  • @kim15742
    @kim15742 5 років тому +55

    This guy is so enjoyable to watch!

  • @hitlin37
    @hitlin37 8 років тому +76

    "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

  • @jaredmulconry
    @jaredmulconry 8 років тому +25

    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.

  • @user-ov5nd1fb7s
    @user-ov5nd1fb7s 2 роки тому +5

    "It works better if it is turned on."
    I almost had my coffee coming out of my nose.

  • @disk0__
    @disk0__ 6 років тому +16

    This is actually a presentation on banter flow

  • @dave_oleksy
    @dave_oleksy 2 роки тому +3

    It just gets better every time I watch it!

  • @numv2
    @numv2 8 років тому +28

    That guy is brilliant.

  • @llothar68
    @llothar68 6 років тому +33

    He is the Chuck Norris of C++ Programming

    • @kuhluhOG
      @kuhluhOG 4 роки тому +2

      yes, and even is one of the inventors of another language

  • @BGroothedde
    @BGroothedde 4 роки тому +5

    A great presenter and an interesting subject.

  • @acmdz
    @acmdz 8 років тому +19

    His jokes are the best.

    • @ce5983
      @ce5983 11 місяців тому +1

      I said no refunds 😅😂

  • @vonkruel
    @vonkruel 8 років тому +3

    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.

  • @ecosta
    @ecosta 3 роки тому +1

    Finishing presentations at the last minute... Been there.

  • @ZiadHatahet
    @ZiadHatahet 8 років тому +2

    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]

  • @oligophagy
    @oligophagy 8 років тому +11

    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.

  • @Max-ob8gq
    @Max-ob8gq 6 місяців тому

    🤗thank you Andrei 🤗

  • @gauravarya8952
    @gauravarya8952 5 років тому +4

    nice anonymous variable trick at 22:44

  • @hl2mukkel
    @hl2mukkel 6 років тому +8

    This guy is absolutely hilarious!

  • @sandrok14
    @sandrok14 5 років тому +3

    Can someone recommend some beginner-intermediate talks on this channel? Because this is too complicated for me as an early intermediate

  • @GeneralBolas
    @GeneralBolas 8 років тому

    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.

  • @minecraftermad
    @minecraftermad 3 роки тому +1

    But if copy file fails no file gets copied and then the deletion night succeed which would mean files are gone right?

    • @0xbenedikt
      @0xbenedikt 2 роки тому

      Yeah, but copy throws, if something goes wrong and then exits the function before any cleanup will be done.

  • @ThorX89
    @ThorX89 8 років тому +1

    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.

    • @AxelStrem
      @AxelStrem 8 років тому +7

      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:)

  • @mihailmihaylov988
    @mihailmihaylov988 8 років тому

    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?

  • @Vermilicious
    @Vermilicious 4 роки тому +5

    He's a good presenter, but I fell off the wagon when he started with the macros.

  • @ZiadHatahet
    @ZiadHatahet 8 років тому

    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]

    • @platin2148
      @platin2148 7 років тому +2

      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.

  • @matthewnoel2781
    @matthewnoel2781 5 днів тому

    Room full of computer geeks and there's an issue with the slideshow. Classic.

  • @mihailmihaylov988
    @mihailmihaylov988 8 років тому +1

    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.

  • @minecraftermad
    @minecraftermad 3 роки тому

    Id name it on_next_scope_fail but that's because im new to code

  • @user-rw2cx3xj4z
    @user-rw2cx3xj4z 8 років тому +1

    You should definitely look at D ;)

  • @georgeshopov8504
    @georgeshopov8504 8 років тому +5

    This approach makes a good spaghetti of the code. Good luck debugging that mishmash.

    • @HebaruSan
      @HebaruSan 7 років тому

      Right? 18:25 - "What does this guy do?" It creates bugs, because no one understands it.

    •  7 років тому +1

      HebaruSan it's pretty straightforward 😅

    • @seditt5146
      @seditt5146 5 років тому +3

      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.

  • @yash1152
    @yash1152 Рік тому +1

    23:45 watch later

  • @douggale5962
    @douggale5962 8 років тому +5

    I hate macros too.

    • @tikabass
      @tikabass 7 років тому +6

      I don't like typing the same thing over and over....

  • @ZiadHatahet
    @ZiadHatahet 8 років тому

    ... the program will fail to compile. Quite awesome.

  • @mihailmihaylov988
    @mihailmihaylov988 8 років тому +9

    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.

  • @QuentinUK
    @QuentinUK 8 років тому

    ok

  • @mihailmihaylov988
    @mihailmihaylov988 8 років тому +2

    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.

    • @walter0bz
      @walter0bz 7 років тому +1

      lisp is elegant but you pay in runtime cost

    • @tetramaximum
      @tetramaximum 6 років тому +2

      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.

    • @GeorgeTsiros
      @GeorgeTsiros 6 років тому +2

      walter0bz 99% of performance issues in the real world is because of shit code not because someone used lisp instead of cpp

    • @SeriousAlexej
      @SeriousAlexej 6 років тому +2

      Nah, its because noone uses lisp anyway, lol.

  • @mothafucka
    @mothafucka 7 років тому +4

    Andrei is boring as usual...

  • @CartoType
    @CartoType 8 років тому +3

    I gave up after five minutes of waffle and facetiousness. This is not the way to do a presentation.

    • @KristoffelPirard
      @KristoffelPirard 7 років тому +5

      Though I agree with the style-dismay, I watched it out. It was worth it.

    • @ihatenumberinemail
      @ihatenumberinemail 7 років тому +1

      You've got to suffer through the waffle, it's pretty good.

    • @tetramaximum
      @tetramaximum 6 років тому +17

      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.

    • @xarcaz
      @xarcaz 6 років тому +10

      "Waahhhhhh, wahhhhhhhh, waaaahhhhh...!" -Graham Asher, -2015

    • @ce5983
      @ce5983 11 місяців тому

      The introductory waffle and facetiousness (which I enjoyed and glad was recorded for posterity) ends and the material of the talk @6:00