Live data from Hacker News

Fun with C++26 reflection: Keyword Arguments

pydong.org

101–110 of 147 posts

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

#101
post #81

Earlier quoted context omitted.

Personally, I write the simplest subset of C++ I possibly can at all times. Loops, variables, classes and the STL library when useful. The more advanced features you use, the easier it is to make subtle mistakes, confuse someone who hasn't seen that feature before, or just make everyone working on the software wary of ever touching it.

>> I write the simplest subset of C++ I possibly can at all times. Loops, variables, classes and the STL library when useful. That stating that is not stating the obvious, shows how screwed we are. Indeed, why use things that are not necessary? "Just because you can"? And still I find everywhere programs less than 1000 lines of code, that can be written maybe in 10 lines of python, but in C++ they use templates, inhe…

Those 1000 lines of what can be 10 in python are a good thing when the total code base is 10million lines and you need all those obscure corners. However many people hear that and decide that everything should be the 1000 line template/inheritance mess instead of 10 lines because their code base is multi-million lines line, when in reality most of your code will never need all the advantages the complex 1000 line solution gives.

There are places I have that 1000 line template mess that nobody can understand in less than a month of staring at it (including me and I wrote it!) because it is the right answer. Most of the time I don't write that because it is hard and there is no advantage, but once in a while it is the right answer to a complex problem. Those 1000 lines can turn many many 100 line problems into 5 line problems and so overall be a net reduction when done right.

The longer I write code the less use I have for inheritance. Templates are still useful.

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

#102

Earlier quoted context omitted.

Sockets has been in the work for the last 15 years. We almost got asio in the standard. There is significant interest in this, but also monumental bikeshedding. A GUI proposal also was in the work for a while, then dropped because of lack of interest. Threads definitely belong in the standard. Just because some platforms can't implement everything it doesn't mean the standard should be the minimum common denominator.…

> A GUI proposal also was in the work for a while, then dropped because of lack of interest. Are your sure? I can remember proposals for 2D graphics, but I have never heard of a GUI proposal. Graphics is only concerned with drawing things on a canvas. GUIs are about, well, graphical user interfaces which also involve user input, even handling, window management, etc.

The closest I think they got to a concrete proposal was web_view (https://wg21.link/p1108).

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

#103

Earlier quoted context omitted.

Personally, I write the simplest subset of C++ I possibly can at all times. Loops, variables, classes and the STL library when useful. The more advanced features you use, the easier it is to make subtle mistakes, confuse someone who hasn't seen that feature before, or just make everyone working on the software wary of ever touching it.

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!. :)

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

#104

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…

The fascination i sort of get - sometimes rabbit holes are fun to jump down if you have time. I'm working on a satisfactory node modeling tool for fun, and built one of the stores (I have a few different stores) using CRDT's and added collaborative support over webrtc. Is it practical? The result, yes. The process - no, it's a total waste of time and energy compared to much simpler alternatives. No question. Is it fu…

> C++ exposes all this complexity because it's not willing to break anything, ever.

That is also why people use C++ for large complex problems. Not doing that is why python3 took forever to replace python2. When you have a lot of code that works it isn't worth the money to rewrite it if you can help it.

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

#105

Earlier quoted context omitted.

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 t…

> 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. Find me a single language that has an included GUI that anyone uses. I'll wait. Even VB.NET, for which building GUIs was its entire reason to exist at all, has multiple GUIs officially , they couldn't even stick to one. This i…

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

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

#106
post #21

I am scared by what C++ people think is fun.

What do you do with your Friday nights?

I rewrote the boot sector on a floppy drive in raw machine code (not assembly, I wrote the bytes by hand) before trying to see how I could abuse C++.

I consider the above normal engineering/hacking and wonder why someone who wouldn't think the above is fun is doing reading hackernews.

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

#107

Earlier quoted context omitted.

Sockets has been in the work for the last 15 years. We almost got asio in the standard. There is significant interest in this, but also monumental bikeshedding. A GUI proposal also was in the work for a while, then dropped because of lack of interest. Threads definitely belong in the standard. Just because some platforms can't implement everything it doesn't mean the standard should be the minimum common denominator.…

> A GUI proposal also was in the work for a while, then dropped because of lack of interest. Are your sure? I can remember proposals for 2D graphics, but I have never heard of a GUI proposal. Graphics is only concerned with drawing things on a canvas. GUIs are about, well, graphical user interfaces which also involve user input, even handling, window management, etc.

You might be right and I might be misremembering. I thought there was a some point a subcomittee looking into GUIs in addition to the 2d graphic proposal.

edit: I think SG13 was supposed to look into GUIs at some point, but with even the 2d graphic proposal failing, it was disbanded.

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

#108

Earlier quoted context omitted.

> A GUI proposal also was in the work for a while, then dropped because of lack of interest. Are your sure? I can remember proposals for 2D graphics, but I have never heard of a GUI proposal. Graphics is only concerned with drawing things on a canvas. GUIs are about, well, graphical user interfaces which also involve user input, even handling, window management, etc.

The closest I think they got to a concrete proposal was web_view ( https://wg21.link/p1108 ).

Interesting! AFAICT this would allow to run some JS code in a web browser, right? One thing I don't understand:

> Each web_view class instance represents an independent, asynchronous web-content interface. The provided web_view shall support content complying with the [HTML5], [PNG], and [ECMAScript] standards.

Who is supposed to provide the runtime?

Also, it shows how to call a JS function and get the result back in C++, but how would you interface with C++ from within JS (e.g. in an event handler)?

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

#109
post #105

Earlier quoted context omitted.

> 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. Find me a single language that has an included GUI that anyone uses. I'll wait. Even VB.NET, for which building GUIs was its entire reason to exist at all, has multiple GUIs officially , they couldn't even stick to one. This i…

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.

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

#110
post #90

Earlier quoted context omitted.

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.

In a general case you can't do that with separate compilation. [0] struct A { A(A*); }; A* f(struct B *b); struct B { A a1; A a2; B(): a1(f(this)), a2(f(this)) {} }; //in a different translation unit A* f(B *b) { return &b->a1; //or a2, we don't know } [0] https://godbolt.org/z/xMb64ssYK

Your code snippet does not use the designated initializer feature that this comment thread is talking about.

Furthermore your code possibly contains undefined behavior depending on the behavior of the constructor of A.

Post reply on HN