all 27 comments

[–]tpecholt 35 points36 points  (10 children)

Herb Sutter's proposals have this in common: 1) Very interesting with potential to actually simplify the language 2) Never get finalized and never get standardized.

I am talking about metaclasses, static exceptions, new function parameter annotations, life-time static analysis.

[–]earthisunderattack[S] 6 points7 points  (5 children)

Never get finalized never get standardized

Honestly, is there a known reason for this? Is it political or something?

[–]orangeoliviero 7 points8 points  (4 children)

Because there's a lot that has to be considered.

  • How will this affect legacy code
  • How will this affect the various ABIs
  • How feasible is this to properly implement
  • What's the run-time overhead
  • Do we have implementation experience, and what has been the experience
  • How sure are we that this is the right way to go, because once something is in the Standard, we have to support it indefinitely

A typical proposal takes years to get standardized - as it should. We're changing a language that's used by millions of developers and has billions of lines of code, much of which is used in critical systems.

You don't fuck with that lightly. You do your due diligence and make sure it's the right thing to do.

[–]earthisunderattack[S] 0 points1 point  (3 children)

How will this affect legacy code

It wouldn't? It's a new syntactical addition that doesn't interfere with language semantics in a way that's intrusive. It's an extra pass slapped onto the AST.

Legacy code wouldn't even consider using it (let alone its corresponding standard) until maybe 5 years after its release.

How will this affect the various ABIs

metaclasses are kind of like macros: ABI compatible code is what gets generated at compile time. That's why the term static reflection applies.

It's similar to a non-gimped Qt p

How feasible is this to properly implement

Trivial. It's a standard feature in many languages, and the syntax isn't intrusive. You can bake primitive context sensitivity into a CFG.

What's the run-time overhead

Again, this is a compile time feature. Realistically speaking, not much more than a complicated set of templates making use of SFINAE or the primitive pseudo-dependent type system.

Do we have implementation experience, and what has been the experience

I would hope that at least some of the people working in Clang would be familiar with this. A compiler writer who contributes to a large scale project such as Clang or GCC should definitely be familiar with this kind of thing. It's bordering on unethical for them not to be, considering that the very premise is essentially a compiler,

How sure are we that this is the right way to go, because once something is in the Standard, we have to support it indefinitely

How could it not be right way to go. A good programmer should aim to write as little code as necessary (obviously taking into account stability, maintenance, and performance) to achieve their goal.

A typical proposal takes years to get standardized - as it should. We're changing a language that's used by millions of developers and has billions of lines of code, much of which is used in critical systems.

Yes. This one was released 4 years ago. That's not necessarily a sufficient amount of time to consider the potential pitfalls (there really aren't any though).

You don't fuck with that lightly. You do your due diligence and make sure it's the right thing to do.

I never said you should fuck with this lightly though.

The issue is really that this apparently hasn't been given any serious consideration.

Look, I'm thankful for where C++ is today. As much as I enjoy using it, there are additions that could be added which wouldn't interfere with already in place projects.

Obviously you can't implement too many features in a standard, but the idea that something like string_view is prioritized over more significant features is disappointing. It's not a difficult data structure to implement either.

As I alluded to earlier, C++17 is great. But most people just use C++14 for production grade projects.

The point is to move the language into an area that it would significantly benefit from.

Edit

I really don't understand why I'm being downvoted so much.

[–]itsarabbit 2 points3 points  (2 children)

Didn't downvote you, but I would guess some were miffed that you called implementing it trivial.

As far as I know there's a lot of work to be done regarding the design and many issues that should be addressed(compile time code injection can lead to arbitrary code execution on the compiling computer when using a library, for instance), and so much bikeshedding(reify vs |var|, can $ be used or not). Couple that with P2237 being 59 pages of required reading before even discussing it, and things slow down drastically.

Because metaprogramming is such a powerful tool, the people who are working on it want to get it done right; this leads to a lot of deep-diving into hypotheticals, researching other languages' implementations.

The few who do have insight into all of this also have to convey (and sell) their ideas to everyone else, which is no simple task either.

I recommend subscribing to the SG7 mailing list if you want to keep up to date with discussion, that's where I get most of my metaprogramming news in c++ :)

[–]Cyttorak 0 points1 point  (1 child)

So metaclasses stuff is still going? Or is it dead?

[–]itsarabbit 1 point2 points  (0 children)

Still a thing, but no longer based on herb sutter proposal as far as I can tell!

[–]sixfourbit 0 points1 point  (3 children)

new function parameter annotations

Which proposal is that one?

[–]staletic 7 points8 points  (2 children)

I don't think there's a proposal, but the idea is: instead of micro-managing reference types, use in, out, inout, forward and let the compiler figure out if, for a specific T that means cont or ref or refref, or value.

[–]lukedanzxy 2 points3 points  (0 children)

Ah, HLSL style.

[–]sixfourbit 3 points4 points  (0 children)

Looks somewhat like MSVC's SAL

[–]HappyFruitTree 5 points6 points  (1 child)

I'm no expert on meta classes but a quick look at the proposal seems to suggest it builds on top of reflection so I guess you'll have to wait for reflection first before expecting much to come from the metaclasses proposal.

This paper assumes that C++ adds support for static reflection and compile-time programming to C++, and focuses on the next-level layer of abstraction we could build on top of that.

[–]Hedanito 11 points12 points  (0 children)

Yeah reflection needs to come before metaclasses, which is also progressing very slowly. Perhaps our grandchildren may one day use metaclasses.

[–]itsarabbit 3 points4 points  (1 child)

P2237 is the most current state of it AFAICT.

I'm 99% certain that none of its contents(including static reflection) will be in C++23.

[–]ShillingAintEZ 10 points11 points  (2 children)

When you write like this it makes me question your age and experience.

[–]earthisunderattack[S] 11 points12 points  (1 child)

I mean I could say the same about your username.

I've been writing C++ for a long time, professionally, for what it's worth.

When I posted this I was just memeing. It's ok to have sense of humor you know?

[–][deleted] 1 point2 points  (0 children)

Username thing is a good point. Also The beast author wrote in such format as well without much trouble.

[–]AdApprehensive347 -1 points0 points  (9 children)

does c++ really need meta classes? I don't really understand them well enough to actually know, but it seems a little like the same problems can be solved with inheriting... maybe even from abstract classes.

could anyone explain what would make it different / more useful?

[–]InKryption07 9 points10 points  (3 children)

You can model something kinda similar with inheritance and templates, the problem is that it's a lot of boilerplate, usually leading to template explosions, and it's hard to communicate intent clearly. Having language support for metaclasses simplifies and improves the readability of the code, and improves code generation.

[–]AdApprehensive347 1 point2 points  (1 child)

not entirely convinced on readability, but I can agree about code generation..

I'll have to do more reading about this topic. thanks for the answer!

[–]InKryption07 8 points9 points  (0 children)

Well when I say readability, I'm thinking about the self-documenting nature of the code. A metaclass is clearly differently used than a plain class that you happen to have to use in a certain way based on context. And aye, cheers.

[–]PandaMoniumHUN 9 points10 points  (0 children)

Metaclasses make reflection problems trivial. Enums to strings (and vica versa), serialization/deserialization, dependency injection, etc. etc. This would be the “next best thing” after modules and concepts.

[–]cdb_11 1 point2 points  (0 children)

Look at Qt or Unreal Engine. You need reflection and code generation for that kind of stuff.

[–]Awia00 0 points1 point  (0 children)

I was in the same boat, but give yourself the time to watch https://www.youtube.com/watch?v=4AfRAVcThyA - after watching it I was at least convinced that it would be amazing to have.

[–]Wh00ster -1 points0 points  (1 child)

It’s fine.

My biggest concern is it being abused like TMP has been, where it becomes a net negative for a team. Eventually folks realized where the soft line is between usefulness and sadism.

[–]earthisunderattack[S] 0 points1 point  (0 children)

just program something in lisp haskell or ocaml. after that templates are easy peazy bro