Why does RTTI seem to frown?

It seems that everywhere I read that either the library can boast if RTTI is not needed, or the article advises against its use. What is wrong with this and why is it so unnecessary?

thanks

+4
source share
6 answers
  • Because use usually means that you undermine polymorphism ( if (type is foo) { do this; } else if (type is bar) { do that; } else ... ), which usually means that you constructed yourself in a corner and you need to rethink your design.

  • Since the authors of C ++ compilers put a lot of effort into optimizing polymorphic behavior, and even more so to optimize the use of RTTI.

+14
source

C ++ allows many static tricks with templates, thereby reducing the need for RTTI (everything at compile time is general, but specific at run time).

In contrast, the SmallTalk-like OOP method for working with classes requires dynamic binding and RTTI.

C ++ allows both, but excessive dynamic_casts and virtual functions can and do degrade performance.

+2
source

Many truncated embedded systems will have simpler / smaller implementations that do not support RTTI. If your library does not need this, you are ported to other systems.

+1
source

RTTI represents a big role for CRT (C Runtime). C ++ developers support execution speed. The last thing you need is to implement a runtime environment that will relatively slow down the application.

0
source

RTTI does what globally unique ordinals specified during development can do much better. Two reasons not to use RTTI.

Performance: It's not trivial to come up with an implementation that scales, and also use ordinals / enumerations to represent types, and since you don't want namespace collisions, you should use strings, not just strings, globally unique strings. In scripting languages, everything is a string, so in these languages โ€‹โ€‹there is no frown.

Elegance Design: working with fundamentals based on ordinals, and if you use it, most likely you had the foresight for the correct development of the system from the very beginning. Such a design is almost always better than relying on RTTI.

-1
source

This is not good (do not use RTTI). Binding should be as late as possible (but no later). The need for speed and energy consumption limits you to how late you can communicate, but developments in chip technology mean that more and more projects can afford to bind later. Later binding allows you to make constructive decisions later, when additional information is available that allows you to make more informed decisions.

-1
source

All Articles