Live data from Hacker News

Fun with C++26 reflection: Keyword Arguments

pydong.org

111–120 of 147 posts

Re: Fun with C++26 reflection: Keyword Arguments

#111

I just don't understand why some people are so fascinated by this. Can you all admit that this is not at all practical? I swear C++ folks like it for the sake of it. No other engineer do this. Only antiques people or whatever. Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?". I was expecting someth…

At this point, you should just switch to JavaScript. The desperation to have the simple ease of JavaScript without having to say you're going near "that terrible language" is twisting C++ into ridiculous loops. I'm serious. It's like a bizarre Victorian relic now.

Ah yes, the language that has no built in support to test if two non-primtive types are equal (& not just objects but arrays of primitives too), that has no proper integer type, whose standard library is thread-bare, and is an exercise in masochism if you don’t transpile it from TypeScript. TypeScript is at least somewhat livable but can we get beyond arguing which terrible language is better?

Re: Fun with C++26 reflection: Keyword Arguments

#112
post #105

Earlier quoted context omitted.

Smalltalk-80 when it was at Xerox PARC, Objective-C at NeXT, VB (native version, not .NET), Hypercard.

That list would be like saying "Java on Android". A single platform's narrow usage of a language != language's standard library having it.

It is the standard library on the platform, of course it counts.

Get Smalltalk-80 reference manual without the UI documentation of its standard library, and no, GNU Smalltalk is not a complete implementation.

Re: Fun with C++26 reflection: Keyword Arguments

#113
post #58
post #37

Earlier quoted context omitted.

Would be happy with a enum that's a named key value. key_enum one_two_three { FIRST = { .name = "first"}, SECOND = { .name = "second"}, THIRD = { .name = "third"}, LAST = { .value = 255, .name = "last"}, };

What is wrong with the following? Do you want type more type safety, e.g. linking the enumeration constants to the array? enum { FIRST, SECOND, THIRD }; struct { char *name; int value; } table[] = { [FIRST] = { .name = "FIRST", .value = 0 }, [SECOND] = { .name = "SECOND", .value = 1 }, [THIRD] = { .name = "THIRD", .value = 3 }, };

I have yet to see a project where there have never been bugs due to someone forgetting to update the metadata attached with the enum when there's a change

Re: Fun with C++26 reflection: Keyword Arguments

#114
post #112

Earlier quoted context omitted.

That list would be like saying "Java on Android". A single platform's narrow usage of a language != language's standard library having it.

It is the standard library on the platform, of course it counts. Get Smalltalk-80 reference manual without the UI documentation of its standard library, and no, GNU Smalltalk is not a complete implementation.

"The standard does not attempt to specify areas where current implementations differ in significant ways. In particular, as the goal statement implies, we did not include graphics, user interface, or database accessing objects in the library."

1997 DRAFT ANSI Smalltalk Standard

https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-ind...

Re: Fun with C++26 reflection: Keyword Arguments

#115
post #93

Earlier quoted context omitted.

You can't easily take the pointer to an other member in a designated initializer. It's still a problem for members that are implicitly initialized by their default member initializer, but that can be sorted out.

I think it is easy enough to be a potential footgun [0]: struct A { A(A*);}; struct B { A a1; A a2; }; void f() { B b{.a1 = A(nullptr), .a2 = A(&b.a1) }; } [0] https://godbolt.org/z/cGaxzh17T

That's a stretch to call it "easy enough", you are explicitly pointing the gun at your foot. That `b.a1` might not be explicitly UB, but that's quite suspect when b's lifetime didn't start yet. Accessing members through `this` in constructors have some special allowance to not make that UB.

Re: Fun with C++26 reflection: Keyword Arguments

#116
post #103

Earlier quoted context omitted.

I have almost entirely removed loops from my definition of the simple subset of C++. Turns out that in nearly every case anytime I think loop I'm able to find a STL algorithm that does the same thing in a more expressive way. I do use lambdas all the time, they are very powerful and so worth learning the complex syntax to make them work. I strongly recommended you add them to your list of things you use all the time…

Remember the master, no raw loops! . :)

No raw loops, no new/delete (malloc/free). The two keys to making C++ a better language for you. You can still run into a lot of foot guns, but the above rules two eliminate a large portion of them.

Re: Fun with C++26 reflection: Keyword Arguments

#117
post #114
post #112

Earlier quoted context omitted.

It is the standard library on the platform, of course it counts. Get Smalltalk-80 reference manual without the UI documentation of its standard library, and no, GNU Smalltalk is not a complete implementation.

"The standard does not attempt to specify areas where current implementations differ in significant ways. In particular, as the goal statement implies, we did not include graphics, user interface , or database accessing objects in the library." 1997 DRAFT ANSI Smalltalk Standard https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-ind...

That is not Smalltalk-80 as originally designed....

Re: Fun with C++26 reflection: Keyword Arguments

#118
post #68

Earlier quoted context omitted.

>Like how struct designated initialisers have to be in order of member declaration due to object lifetime rules or something like that. It matters in which order sub-objects are initialized - if you have a class with the members A and B, and B takes pointer or reference to A in its constructor and does something with A, A better be already initialized. Sub-objects are initialized in the order of their declaration and…

You still don't need to syntactically require same order initialization, it's an easy job for a compiler to reorder things so that all dependencies work out - every language with order independent declarations have to do that for example.

You don't need to require same-order initialization, but allowing people to do different orders will be confusing when actions are reordered behind the scenes. Especially imagine if there are dependencies between the objects you're passing in.

  struct A {
    B one;
    C two;
  };
  struct B {
    B() {
      cout 
Mixing up the order is confusing:

  A{.two=B(),.one=A()}
since `two` is initialized after `one` despite coming before (the comma operator , usually means `expr a` happens before `expr b`.

This case is a little contrived, but run the evolution forward: you can have members that depend on each other, or have complex initialization logic of their own. There, debugging the specific order of events is important.

Re: Fun with C++26 reflection: Keyword Arguments

#119

I just don't understand why some people are so fascinated by this. Can you all admit that this is not at all practical? I swear C++ folks like it for the sake of it. No other engineer do this. Only antiques people or whatever. Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?". I was expecting someth…

i think it's neat that you can do that

i'm going to stick to C, to prevent it from compiling, though

Re: Fun with C++26 reflection: Keyword Arguments

#120
post #42

Earlier quoted context omitted.

It was C99. It took C++ 21 years to copy it.

It's been the primary and most annoying interop issue for us when we have to integrate C++ code into our primarily C codebase (= build some pieces of our code in C++, which necessarily has to interact with at least our header files). (Second place: differences in available GCC/clang compiler extensions between C and C++ [our software does not support Windows/MSVC], third place: differences in what casts are permitted…

My number one issue are VLA parameters

int foo(int N, char buf[N]);

which I like to use because they improve warning messages, but they are not accepted in C++.

Post reply on HN