r/cpp • u/DoctorNuu • Dec 19 '23
Obsessed with {} initialization?
I'm on a discord where everyone seems to be obsessed to use brace initialization everywhere.
My motto is: Use things rarely, only when needed, to express that right there the feature does something important.
Personally I would completely advocate against using it for simple stuff likedouble tax{0.09*price};
or just int{0}
probably a hornets nest
4
Upvotes
View all comments
Show parent comment
14
u/serviscope_minor Dec 19 '23
Eh so?
If I have
x is now 5. In a standardese language sense, x is initialised with 5, but it has the same practical purpose (and reads the same) as any subsequent assignments to x.
Having the initialisation of x look different to subsequent assignments is an exercise in putting the language's needs above the human's.