← Back to context

Comment by rramadass

18 days ago

Your example is disingenuous. What you are stating is the obvious trivial way of doing something when your objective is actually quite different.

You can get exactly what you are asking for in C++ using techniques of static polymorphism and CRTP pattern (https://en.wikipedia.org/wiki/Curiously_recurring_template_p... and https://en.wikipedia.org/wiki/Barton%E2%80%93Nackman_trick) along with traits and dynamic dispatch (if needed).

For great examples of the above, see the classic Scientific and Engineering C++: An Introduction with Advanced Techniques and Examples by Barton & Nackman (1994).

What you're describing is needing to use specific verbose patterns to opt out of the defaults that do more complex things under the hood, whereas they're describing how C and Rust do not do those things by default and instead let you opt into them. It's not disingenuous to point that out.

  • Not quite.

    What i am pointing out are neither complex nor any magic under-the-hood. They are simply techniques in the C++ repertoire well-known since the early 90's and used in all high-performance C++ libraries.

    tialaramex made a big deal out of overheads in C++ dynamic dispatch (which incidentally are pretty minimal) using a trivial example, when performance focused (both time and size) C++ programmers do not use it that way at all. Modeling in C++ can be done in any number of ways and is driven by specific perspectives of the end goal.