CppCon 2018: Andrei Alexandrescu “Expect the expected”

CppCon 2018: Andrei Alexandrescu “Expect the expected”

CppCon

5 лет назад

60,431 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Евгений Захаров
Евгений Захаров - 11.07.2023 21:45

I really expected an expected to be inside the other expected but Andrei failed my expectations!

Ответить
Mason DeRoss #ActuallyAutistic
Mason DeRoss #ActuallyAutistic - 25.06.2023 19:54

Update: We finally have expected in C++23!

Ответить
belst R
belst R - 06.07.2022 12:32

I think a solution to expected<void, E> would be to annotate functions returning that as nodiscard, that way you would at least get a compiler warning if you just ignore the return type

edit: ok exactly that question was asked right at the end

Ответить
Triangles!!!!!!!!!!!!!!!
Triangles!!!!!!!!!!!!!!! - 08.03.2022 00:31

Wouldn't returning `expected<void, error_type>` show less intention than returning `optional<error_type>`?
Since in the end both return types say 'this function might return an error or nothing'.
My guess is, that `expected<void, error_type>` would be preferred only for homogeneity among other return types.

Ответить
Terry A. Davis
Terry A. Davis - 12.03.2021 07:36

3 years later and this still is in proposal.

Ответить
Elite7555
Elite7555 - 22.03.2020 06:52

Andrei is a phenomenal speaker!

Ответить
Johhy Gaddar
Johhy Gaddar - 21.06.2019 09:07

Ugly shitty language

Ответить
John Doe
John Doe - 18.03.2019 13:12

found local choreography normal (cause they do java instead of c++) LOL

Ответить
Petar Dambovaliev
Petar Dambovaliev - 02.03.2019 00:05

"I heard you not saying", LOL.
I am going to use this quote from now on.

Ответить
Petar Dambovaliev
Petar Dambovaliev - 01.03.2019 23:29

The guy is funny

Ответить
MaceUA
MaceUA - 22.02.2019 18:38

I don't understand why they discarded the approach with storing an std::exception_ptr instead of some template argument E inside the Expected. If I remember correctly, that's what Andrei initially proposed a few years ago when presenting the idea of Expected. That approach looked much cleaner (no need to specify two template arguments) and more flexible (you could store any kinds of exceptions in the Expected, even if the function "throws" multiple unrelated exception types).
Is there an explanation why this decision was made now?

Ответить
MaceUA
MaceUA - 22.02.2019 16:56

Slide 28: it might be better to use std::conjunction to short-circuit the expression inside enable_if.
Also, another part of homework for implementers: make this swap() function conditionally noexcept, where it can be. That could help some other generic code to be more efficient.

Ответить
Omnifarious
Omnifarious - 09.02.2019 05:19

He's absolutely right about how expected should behave, down to the last detail. I really hope the standards committee makes it and does it the way he recommends, right down to not having operator *.

I've been thinking through how to do error handling for a hypothetical C++ wrapper to the POSIX/Linux api. I came to the exact same conclusion for how it should be done.

Compilers are good enough at flow analysis to emit diagnostics if you never check things like `expected<void>`, or even if you ignore any exected.

Ответить
bloody_albatross
bloody_albatross - 26.11.2018 05:36

If you write your application using expected with exception handling deactivated, then .value() is surly also undefined behavior?

Ответить
mrlithium
mrlithium - 03.11.2018 13:08

I love the way he presents! Very conversational, and natural, while still hitting all the salient details and not just outright repeating whats on the slides. And funny, throwing in jokes - not nervous at all. He also anticipates our possible thinking stumbling blocks and even addresses the natural tangential side-thoughts. Totally comprehensive. And from a non-native speaker of English, it's all the more impressive. What a legend! (much better than Titus - total opposite in fact) - almost on Bjarne's level. Big fan of his contributions too. He really sees the big picture and doesn't get distracted.

Ответить
Operation Darkside
Operation Darkside - 02.11.2018 19:24

1. Great and entertaining talk.
2. There's a ')' missing in slide 30, I think.

Ответить
Zhao Li
Zhao Li - 02.11.2018 17:30

it is mimicking the NAN convention in floating point computation.

Ответить
Zhao Li
Zhao Li - 02.11.2018 17:29

yet another way to handle errors in cpp?

Ответить
Tim Seguine
Tim Seguine - 02.11.2018 13:56

I finally decided that Andrei's voice reminds me of Triumph the insult comic dog. "This code is really great... for me to poop on!"

Ответить
Maxime Tournier
Maxime Tournier - 02.11.2018 11:12

where is monadic bind operator?

Ответить
Lilian
Lilian - 02.11.2018 00:14

Around ~ minute 4 it was clear that this will sound like C++'s version of Rust's "Result<T, E>".

Ответить
MrGDTEX
MrGDTEX - 01.11.2018 22:07

Can someone explain, why did they use placement new instead of simple initializing in constructors?

Ответить