CppCon 2018: Nicolai Josuttis “The Nightmare of Initialization in C++”

preview_player
Показать описание


After introducing uniform initialization with C++11, there are at least 5 ways in C++ to initialize an object.
Each have them has different rules, different effects, and different usage depending on the context and goals.
The situation is so confusing that today nobody can tell anymore which type of initialization to teach to beginners.
That's nothing but a disaster.

This talk will discuss the different forms of initialization, compare them to know when to use which, discuss what changed with C++14 and C++17 and what still has to change, and finally what to teach now to beginners.
I promise a source of trouble and discussion.

Nicolai Josuttis
IT Communication



*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

The endless attemps to square the circle

GamingDemiurge
Автор

This is the kind of stuff that makes me want to quit C++ forever

Astfresser
Автор

"If you're lucky, you get a core dump"

EllAntares
Автор

"Always Auto Ampersand Ampersand" fucking slayed me.

IYXandanYI
Автор

It's almost incredible how retro-compatibility always makes things worse over time.

ecosta
Автор

Thanks for posting this, i was gonna watch it, but read the comments and realized i don't need to be more confused than i am already. Getting into C++ in 2023.

artiekushner
Автор

I'm more confused now than I was before

Drk
Автор

What a clusterfuck of complexity. Holy shit.
Legends has it that bjarne steoustrup created c++ to increase the demand of programmers as things were getting simpler.

aiman_yt
Автор

Would love to see a C++2, with all the backwards compatibility thing removed

Автор

49:02 I wouldn't call that a fix...
If I delete a constructor, I don't want it to be used, no matter how.

kuhluhOG
Автор

C++ is evolution and not intelligent design.

mzimbres
Автор

seems to be the best way to avoid confusion is to keep the old basic initialization
One of the advantages is readability, second is avoiding bugs
After all, what are we messing with is merely INITIALIZATION
Why waste so much time on such an issue

avivran
Автор

C++ is like Perl then? :-)
Fifty shades of initialisation: what shade do you prefer? Please be explicit.

steveragnar
Автор

Initializer lists were a mistake. It was an introduction of a new literal type without any syntactic differentiation to indicate that it was a new literal type, and so the compiler has to guess from context. It's a lot like the "Is this a constructor call or a function declaration?" problem you got with parenthesis based initialization.

They should simply have forbade = initialization for any type that wasn't initializer_list, then they could've just then said that ordinary C arrays have a built-in constructor from an initializer_list.

And an = sign should be required for aggregate initialization from an initializer list.

Omnifarious
Автор

This explains why learning c++ is so frigging hard.

buddyairguy
Автор

Stay positive and let that smile light your way.

Donald_ai
Автор

40:03 has missing curly brace ('}') - e.g. std::vector<std::string> v05 = {{"1, "2", "3"}; // OK .... but since the slide was showing various levels of curly braces, and there was already {"1", "2"} shown as exampl, I guess I can assume this is {{"1", "2"}}. Just FYI

DimiterStanev
Автор

11:40 That already exists in C++17 via template type deduction.
std::initializer_list l = {42};
std::initializer_list l{42};
Both will automatically deduce type int.

Mirality
Автор

Am I alone to find that taking {1, 2} as a complex<double> (other than by backward compatibility) is weird?
If the construct was explicit, we would use instead {complex{1, 2}, complex{3, 4}}, which IMHO is the correct way to do it, for vectors and for arrays.
Explicit is safer than implicit.

botetescribavicentej.
Автор

The Legend (=, Thank you so much Mr Nikolai! I love your books, thank you!

AA-emlw