News for hackers. Stuff that matters.
Re:Initialization in C++ is Seriously Bonkers by ori_b on Saturday January 05, 2019 @02:04PM (#18833531)
> Complex? Yes, but that's what you get with C++:

Congrats on successfully summarizing the complaint.

It's not mysterious, but it's gratuitously complex. And this is only variable initialization.

Re:Initialization in C++ is Seriously Bonkers by tines on Saturday January 05, 2019 @02:09PM (#18833561)
You ended the quote early, and my sentence went beyond the article. I said:

> that's what you get with C++: very fine control of program semantics, benefit being expressive libraries.

It's not gratuitous because you can't remove much of it without losing power or expressiveness (and still remain a C).

Also, by complex I didn't mean complicated.

Re:Initialization in C++ is Seriously Bonkers by esrauch on Sunday January 06, 2019 @03:50AM (#18837343)
It doesn't really seem necessary for "A a = A{}" and "A a = {}" to be different things to have power and expressiveness. It really seems like uniform initialization covered just one arbitrary case while making other cases even less uniform.
Re:Initialization in C++ is Seriously Bonkers by jblow on Saturday January 05, 2019 @02:09PM (#18833559)
Indeed.

If just setting integers is this complicated, what do you expect to happen when you are trying to solve real problems?

Re:Initialization in C++ is Seriously Bonkers by kllrnohj on Saturday January 05, 2019 @02:23PM (#18833640)
The parsing details can be complicated while the end result can be simple. Consider the actual C++ example that would be taught & used in practice:

   struct A {
     int i = 0;
   }
   
   int main() {
     A a;
     std::cout << a.i << std::endl;
   }
Hey, look, done. And you only had to teach a single thing - default initialization. Which has an obvious & simple syntax. The int i is always initialized to 0, as intended, and it's in a single spot at the point of declaration.

Now try doing that in C. Oh, wait, you can't. The closest you can get is this mess:

   struct A {
     int i;
   } const default_A = {0};
   
   int main() {
     struct A a5 = default_A;
     printf("%d\n", a5.i);
   }
Which requires you to know that you can declare a type & an instance of that type in a single statement, why that const is where it is and why that's important here, how braced initialization rules work, that you need to always remember to manually initialize to your default_A, and that %d means 'int'. And the compiler won't help you with any of this except for the %d part if you get it wrong.
Re:Initialization in C++ is Seriously Bonkers by jstimpfle on Saturday January 05, 2019 @02:26PM (#18833653)
> Which requires you to know that you can declare a type & an instance of that type in a single statement

    struct A {
        int i;
    };

    const struct A default_A = { 0 };
Why didn't you try the obvious simple thing first?

The whole undertaking is pointless in any case. Why would you need default values (i.e. templates for constructors) baked in? The only reasonable default value, sometimes, is all-zeroes (or all-ones...).

Now, constant data (i.e. things that contain more useful information than just "it's the default because a real value is missing" -- and that aren't copied around pointlessly) is another case, and C's plain old value initializer syntax (as demonstrated above) serves it perfectly well.

Re:Initialization in C++ is Seriously Bonkers by kllrnohj on Monday January 07, 2019 @09:07PM (#18852454)
> The only reasonable default value, sometimes, is all-zeroes (or all-ones...).

That's very false. Consider a basic string container with a small-size optimization. The default value for capacity is neither 0 nor 1, but the size of the inline array.

Similarly it could be an enum value, and the default for a given class isn't whatever the 0 value happened to line up with because that's arbitrary anyway. An example being a basic type id of a fixed number of types.

Re:Initialization in C++ is Seriously Bonkers by shaklee3 on Saturday January 05, 2019 @07:44PM (#18835491)
Considering that a vast amount of extremely important software and large projects use C++, I would say it solves real problems nicely. You can get pedantic about features of any language if you want to.