Live data from Hacker News

Show HN: Beautiful Type Erasure with C++26 Reflection

ryanjk5.github.io

11–20 of 64 posts

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#11
post #4

The things people describe as "beautiful" never cease to amaze me... ...but, as they say, beauty is in the eye of the beholder!

I don’t really like much about C++ anymore, but I still enjoy reading C++ articles and listening to C++ podcasts, and I would consider it beautiful. Oftentimes the things I dislike about it are also the beautiful things. The term “beautiful mess” seems appropriate. It’s a bit like a well-kept Victorian home. The amount of work, money, and dealing with discomfort that goes into maintaining one isn’t something I really…

> I would consider it beautiful

I had the same misunderstanding before I get to know CS. that was 30 years ago.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#13
post #8
post #5

Earlier quoted context omitted.

Beauty in C++ may be most similar to lipstick on a pig, but we try our best.

I admire you guy keep trying. I'm also glad I do not write C++ on the daily anymore: luckily my software does not need that kind of performance characteristics.

Yet I imagine your software depends on C++.

Either directly on top of a runtime/compiler written in C++, or as indirect dependency on a C++ compiler toolchain.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#16

What's compilation time like when using it? I see there's an issue in the tracker to get more accurate data, and since it's using an under dev feature in compilers, it's not going to be definitive, but any rough numbers?

I don't have any numbers, but it is pretty slow. You can try making some edits in Compiler Explorer to see for yourself (though that of course has some impact from network requests).

One reason is that, like you said, the feature is still new. Additionally I made pretty liberal use of the std::ranges library in my implementation which has notoriously bad compile times. That could be an area to improve upon.

Another may be a bit more structural. If you want to call myObj.foo() via reflection, you have to linearly search members_of(myObj) for the one named "foo", and then call that. Actual compilers I assume use some kind of hash table.

The hand-waving solution is "put it in a PCH", but I am hoping to put some more effort into optimizing build time here in the future.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#17

in the first example: ``` 10: rjk::duck c{std::vector {1, 2, 3}}; 11: c.size(); // 3 12: 13: c = std::string{"hello"}; ``` Does the assignment on line 13 call the destrucor for the vector of ints created on line 10?

Yes. duck takes ownership of the vector by moving it into its internal storage.

As a bonus, if you tried passing in an lvalue, it will reject the input unless you add the "copyable" trait, so it ends up mitigating some hidden copies.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#18
post #4

The things people describe as "beautiful" never cease to amaze me... ...but, as they say, beauty is in the eye of the beholder!

I don’t really like much about C++ anymore, but I still enjoy reading C++ articles and listening to C++ podcasts, and I would consider it beautiful. Oftentimes the things I dislike about it are also the beautiful things. The term “beautiful mess” seems appropriate. It’s a bit like a well-kept Victorian home. The amount of work, money, and dealing with discomfort that goes into maintaining one isn’t something I really…

> I would consider it beautiful.

If there's something that C++ actually lacks, that's the elegance, grace and beauty. The rest, it's all already there or will be there shortly :)

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#19
post #4

The things people describe as "beautiful" never cease to amaze me... ...but, as they say, beauty is in the eye of the beholder!

I find it hard to see a language as beautiful that’s grown too complex for a single person to hold a complete mental model of.

I used to think that was a personal limitation, until I saw an interview with Bjarne explaining that he used to understand all of it but at this point it’s too big, no one can anymore.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#20
post #18

Earlier quoted context omitted.

I don’t really like much about C++ anymore, but I still enjoy reading C++ articles and listening to C++ podcasts, and I would consider it beautiful. Oftentimes the things I dislike about it are also the beautiful things. The term “beautiful mess” seems appropriate. It’s a bit like a well-kept Victorian home. The amount of work, money, and dealing with discomfort that goes into maintaining one isn’t something I really…

> I would consider it beautiful. If there's something that C++ actually lacks, that's the elegance, grace and beauty. The rest, it's all already there or will be there shortly :)

The problem with that is best described by Antoine de Sain-Exupery's saying "perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." I guess the same goes for elegance and grace...
Post reply on HN