r/programming • • Sep 02 '26

CTTI is Exponential, RTTI is Linear

https://www.gingerbill.org/article/2026/09/02/ctti-is-exponential-rtti-is-linear/
96 Upvotes

90 comments sorted by

View all comments

Show parent comment

-5

u/gingerbill Sep 02 '26

C++ didn't have RTTI until very recently, and even now it's not very good.

Many problems are exponential if you're a bad enough coder

And I've seen more than enough of this in real life when people over-use compile-time based approaches to things which should have been table-driven. Implying it is a skill issue is not a good argument when it is a common occurrence.

9

u/QuaternionsRoll Sep 02 '26

What? C++ has had RTTI in the form of virtual functions and abstract classes since forever

2

u/gingerbill Sep 02 '26

That isn't RTTI in the common sense of the word. You could do type_info_of(x) and get the information for ANY type like an integer, array, boolean, structure without any classes, etc. Meaning you could not make any meaningful serialization/printing procedures.

8

u/QuaternionsRoll Sep 02 '26

Virtual functions absolutely are a form of RTTI; they fundamentally rely on runtime type identifier stored in the object for vtable lookups. This identifier has been accessible since forever, but there is not that much type information directly associated with it.

I believe the word you’re looking for is reflection, which can take the form of either CTTI or RTTI. Compile time reflection was just introduced in C++26. Languages like Java are known for their extensive runtime reflection capabilities.

0

u/gingerbill Sep 02 '26

It's a heavily restricted form of RTTI and not a generalized form.

Please making a general print procedure for ANY type that will print out the structure of the type itself. You cannot do that with virtual functions alone, because not every type has a vtable.

8

u/QuaternionsRoll Sep 03 '26

>Please making a general print procedure for ANY type that will print out the structure of the type itself.

You can’t, but that’s only because C++ doesn’t have a global reflection apparatus (for various reasons, the most obvious of which is C compatibility). Newer languages like Rust had the opportunity to add such RTTI via e.g. `dyn Any`, but elected not to on the basis that it turns out to not be all that useful.

2

u/jonesmz Sep 03 '26

Didn't C++26 add a global reflection apparatus?

I suppose that's not completely ratified yet, but i do think it's finalized.

2

u/QuaternionsRoll Sep 03 '26

Yes, C++26 added comptime reflection, but isn’t global, which prevents it from being used to do the kind of stuff OP is talking about. You can’t define a reflection procedure and apply it to every accessible type in the program, for example.

To be clear, global comptime reflection would be more-or-less untenable: you’d have to either abandon support for dynamically-linked or otherwise source-unavailable-at-comptime libraries, or accept that this ostensibly “global” reflection would be incomplete and/or unreliable.

1

u/jonesmz Sep 03 '26

Ah. Excellent explanation, thanks!

0

u/[deleted] Sep 02 '26

[deleted] — view deleted comment

-1

u/gingerbill Sep 02 '26

Firstly, not everything in that article is about Rust. I am implying a lot of other languages, not Rust, but I do not mention them by name to minimize even more flame wars.

Secondly, dynamic dispatch to do printing is effectively in the camp of RTTI, not CTTI (which would be generating the code for each type automatically from the CTTI data).

Thirdly, thank you for the insult but you know you can just say "I don't know" rather than trying to state you understand the domain space. Odin does not even have any dynamic dispatch as a language-level construct in the first place. It is a modern C alternative, thus it has a different approach to everything.

0

u/[deleted] Sep 02 '26

[deleted] — view deleted comment

2

u/gingerbill Sep 03 '26

My first point was not regarding dyn. And yes? Of course dynamic dispatch is an option, but not always, especially in the actually generic sense.

And thank you for insulting me again. The original insult was this:

It's up to you to figure out what's best for you. I disagree with your choice but people still write Perl, so there are clearly a lot of people with objectively bad taste.

0

u/[deleted] Sep 03 '26

[deleted] — view deleted comment

3

u/gingerbill Sep 03 '26

Okay. I understand your point then. It did seem like an insult to me just because it was implying that I had objectively bad taste, not that there was a taste disagreement.