Live data from Hacker News

Fun with C++26 reflection: Keyword Arguments

pydong.org

51–60 of 147 posts

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

#51

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…

Reflection is spectacularly useful and sorely missed in C++ But because this is C++ the committee designs the most insane and terrible version of reflection possible

Unfortunely so it is with anything committee design, including SQL, C and Khronos APIs as well, it is not only C++.

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

#52
C++ reflection is now good enough that hopefully we’ll start to see more game engines using it to work out components and properties instead of weird macros. jcelerier’s work on things like Avendish really does feel quite fresh and modern, which is not my usual reaction to C++ frameworks. Obviously it’s lagging a good 20 years behind C# et al but we’ve come a long way since IUnknown.

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

#53

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…

This is a nifty little gadget, not a production level feature. C++ lacks a lot of things, but it's objectively cool that you can hack some of them yourself (like kwargs). No one should use this in important code. This is just fun.

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

#55

Earlier quoted context omitted.

Reflection is such an insanely useful tool that pretty much all modern languages have it. As usual C++ is 20 years behind language design and brings terrible syntax. But it is tremendously useful. https://en.wikipedia.org/wiki/List_of_reflective_programming...

The article is about compile-time reflection, which is not nearly as useful as what the Wikipedia article you linked is about. It's only upside is that it is "zero cost" by some definitions of cost. Runtime reflection on the other hand is useful but it also puts up obstacles not easy to overcome. For example it is one major reason we still have no decent ahead-of-time compilation in Java.

Compile-time reflection is by far the most useful

It replaces the plethora of code generators that currently surround C++ like flies

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

#56
post #9

Earlier quoted context omitted.

I've seen cases where people do things like my_func(/*arg1=*/val1,/*arg2=*/val2) And I suppose you could write a validator to make sure that this worked. Or using an anonymous structure in C99, or a named structure in C89. And of course a pointer if you care about register/stack usage etc. I'm not sure what the other options are.

> And I suppose you could write a validator to make sure that this worked. Like this one! https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argu...

Wow I had no idea, that's great!

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

#57
post #13
post #9

Earlier quoted context omitted.

I've seen cases where people do things like my_func(/*arg1=*/val1,/*arg2=*/val2) And I suppose you could write a validator to make sure that this worked. Or using an anonymous structure in C99, or a named structure in C89. And of course a pointer if you care about register/stack usage etc. I'm not sure what the other options are.

>> I suppose you could write a validator to make sure that this worked No need to write it: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argu... Efb

That's great, I wish I'd known about this ages ago

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

#58
post #37
post #28

Earlier quoted context omitted.

Honestly, all I ever want is to be enumerate a struct data member or an enum at compile time, and be able to get the name, type and value of each iterated member. That's it. That's all I want.

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 },
  };

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

#59
post #52

C++ reflection is now good enough that hopefully we’ll start to see more game engines using it to work out components and properties instead of weird macros. jcelerier’s work on things like Avendish really does feel quite fresh and modern, which is not my usual reaction to C++ frameworks. Obviously it’s lagging a good 20 years behind C# et al but we’ve come a long way since IUnknown.

I'm not sure if you mean to have a /s in there, but personally I never really liked reflection.

C# had it but it was also in part because it interop'd with .NET which had C++.NET, VB.NET, F#.NET, VBScript.NET, ASP.NET, Core.NET, Web.NET, Net.NET and so much more .. reflection was an "easy" way to have other dev's interact with each others code as a type of "contract".

I really like C# and what it can do, but having to check if a particular method exists within an external dependency is in part what lead to "dll-hell" .. it's the antithesis to an API and a "software contract" .. honestly it feels like C++26's "reflection" is more an answer to the ABI issue that has plagued C++ since its inception.

If C++ really wants to help "game-engines" or make actual strides, then it should add basic GUI support to the language itself. That'd kill off 90% of the other framework/libraries out there.

As with other parts of the language, you don't -have- to use it .. and since it's trying to be the next Java in it's eternal update path, why not add GUI support at a language level ??? Hell the std::thread just calls pthread_create or CreateThread under the hood anyways, just with a 15+ high stack frame .. why not add GUI!?

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

#60

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…

99% of "modern" C++ is just masturbation and trying to keep up with what other languages had 10 years ago. The introduction of new standards isn't improving any code, in fact it's just causing old code to rot faster as the gap widens between the latest standard and the standards companies actually use.

It's obvious to any developer with even a little experience that less is more, complexity is the enemy. C++ continually embraces complexity, it even appears to encourage it as an opportunity to show everybody else how smart you are.

Post reply on HN