Live data from Hacker News

C++26 Reflections adventures and compile-time UML

reachablecode.com

61–70 of 118 posts

Re: C++26 Reflections adventures and compile-time UML

#61
post #55

Oh man, some of the code in the linked proposal: Old: template struct list {}; using types = list ; constexpr auto sizes = [] class L, class... T>(L ) { return std::array {{ sizeof(T)... }}; }(types{}); New: constexpr std::array types = {^^int, ^^float, ^^double}; constexpr std::array sizes = []{ std::array r; std::ranges::transform(types, r.begin(), std::meta::size_of); return r; }(); I'm so tired of parameter packs…

But the standard library should have had things so that we can write:

    constexpr std::array types = {^^int, ^^float, ^^double};
    auto sizes = std::whatever::transform(types, std::meta::size_of);
which would have been even nicer.

Re: C++26 Reflections adventures and compile-time UML

#62

Whenever I start to feel like a real programmer making games and webapps and AI-enhanced ETL pipelines, I inevitably come across the blog post of a C++ expert and reminded that I am basically playing with legos and play-doh.

Library development and application development are activities of a different kind entirely.

Re: C++26 Reflections adventures and compile-time UML

#63
post #48
post #45

Earlier quoted context omitted.

It would standardize something they've done in an ad-hoc way for decades. They have a library called "reflex" [1] which adds some reflection, and which was (re)written by cannibalizing a lot of llvm code. They actually use the reflection to serialize a lot of the LHC data. It's kind of neat that it works. It's also a bit fidgety: the cannibalized code can cause issues (which, e.g. prevented C++11 adoption for a while…

The library that you refer is not in use for a long time already. The document you pointed out is from 2006 (you can check the creation date). Since then, a lot has changed, and now it is all based on cling ( https://root.cern/cling/ ), that originates from clang and llvm. cling is responsible generates the serialization / reflection of the classes needed within the ROOT framework.

Good catch: I'm confusing reflex and the cling code that came later. All the issues I mentioned are still there in (or caused by) cling though. Either way standardization in reflection would help.

Re: C++26 Reflections adventures and compile-time UML

#65
post #6

Whenever I start to feel like a real programmer making games and webapps and AI-enhanced ETL pipelines, I inevitably come across the blog post of a C++ expert and reminded that I am basically playing with legos and play-doh.

It's the other way around. You are the real programmer and the committee and the "modern C++" crowd are more interested playing with legos instead of shipping actual software. No way anything std::meta gets into serious production; too flexible in some ways, too inflexible in others, too much unpredictability, too high impact on compilation times - just like always with newer additions to the C++ standard. It takes o…

I embrace Modern C++, but slower than the committee, when the big three have the feature.

I really think reflection + annotations will give us the chance to have much better serialization and probably something more similar to Python decorators.

That will be plenty useful and it is going to transform a part of C++ ecosystem, for example I am thinking of editors that need to reflect on data structures or web frameworks such as Crow or Drogon, Database access libraries...

Re: C++26 Reflections adventures and compile-time UML

#66

Earlier quoted context omitted.

The stream of modern C++ features have been a god-send for anyone that cares about high-performance, high-reliability software. Maybe that doesn’t apply to your use case but C++ is widely used in critical data infrastructure. For anyone that does care about things like performance and reliability, the changes to modern C++ have largely been obvious and immediately useful improvements. Almost all C++ projects I know i…

You are sounding like rose tinted glasses are on. I think your glass is half full if you recheck actual versions and features. And mine is half empty in gamedev. Anecdata: A year or so ago I have been in discussion if beta features of C++20 on platforms are good to be used on large scale. It makes it not a sum but an intersection of partial implementations. Anyway it looked positive until we needed a pilot project to…

> One of the projects came back with 'just flipping C++20 switch with no changes causes significant regression on build times

Given that C++20 introduced modules, which are intended to make builds faster, I think just flipping C++20 switch with no changes and checking build times should not be the end of checking whether C++20 is worth it for your setup.

Re: C++26 Reflections adventures and compile-time UML

#67
post #6

Earlier quoted context omitted.

It's the other way around. You are the real programmer and the committee and the "modern C++" crowd are more interested playing with legos instead of shipping actual software. No way anything std::meta gets into serious production; too flexible in some ways, too inflexible in others, too much unpredictability, too high impact on compilation times - just like always with newer additions to the C++ standard. It takes o…

> No way anything std::meta gets into serious production Rust proc macros get used in serious production, even though they're quite slow to compile. Sure, std::meta is probably a bit clunkier, but that's expected from new C++ features as you say.

Sadly, Rust proc macros operate on tokens and any serious macro implementation needs third-party crates.

Compile-time reflection, with good, built in API, akin to C# Roslyn would be a real boon.

Re: C++26 Reflections adventures and compile-time UML

#68

Earlier quoted context omitted.

> No way anything std::meta gets into serious production Rust proc macros get used in serious production, even though they're quite slow to compile. Sure, std::meta is probably a bit clunkier, but that's expected from new C++ features as you say.

Sadly, Rust proc macros operate on tokens and any serious macro implementation needs third-party crates. Compile-time reflection, with good, built in API, akin to C# Roslyn would be a real boon.

Any serious anything needs third party crates. Coming from c++ this has been the most uncomfortable aspect of rust to me, but I am acclimating.

Re: C++26 Reflections adventures and compile-time UML

#69
post #66

Earlier quoted context omitted.

You are sounding like rose tinted glasses are on. I think your glass is half full if you recheck actual versions and features. And mine is half empty in gamedev. Anecdata: A year or so ago I have been in discussion if beta features of C++20 on platforms are good to be used on large scale. It makes it not a sum but an intersection of partial implementations. Anyway it looked positive until we needed a pilot project to…

> One of the projects came back with 'just flipping C++20 switch with no changes causes significant regression on build times Given that C++20 introduced modules, which are intended to make builds faster, I think just flipping C++20 switch with no changes and checking build times should not be the end of checking whether C++20 is worth it for your setup.

> Given that C++20 introduced modules, which are intended to make builds faster

Turning on modules effectively requires that all of your project dependencies themselves have turned on modules. Fail to do so, and a lot of the benefits start to become hindrances (Clang is currently debating going to 64-bit source locations because modularizing in this manner tends to exhaust the current 32-bit source locations).

Re: C++26 Reflections adventures and compile-time UML

#70

Earlier quoted context omitted.

I know your comment was meant as a tongue in cheek funny one but people should not be intimidated/overawed by the size of the C++ feature set. You don't need to know nor use all of them but can pick and choose based on your needs and how you model your problem. Also much of the complexity is perceived rather than real since it takes time for one to understand and assimilate new concepts. You can program very effectiv…

Much of the complexity may be perceived, but much is also real, because of the commitment to backwards compatibility and non-breakage, plus poor default behavior of many things, often due to the C legacy, sometimes due to inopportune choices in earlier versions of the standard. Just think of things like variable initialization with () and/or {} ; or various kinds of implicit casts ; the hoops you need to go through t…

The problem is that many confuse C++ Language expertise (often snarkily called a "language lawyer") with C++ Programming expertise. A famous example is Scott Meyers who is squarely in the first camp and who has publicly stated as not having written any sizeable C++ programs. Given that C++ is quite a baroque language it is important for programmers to focus on the second aspect and slowly build up their knowledge of the first aspect over time (most experienced programmers tend to do this in any language).
Post reply on HN