Date: Fri, 10 Nov 2023 01:21:51 +0000
Hi All,
Test-driven development (TDD) is my de facto standard for writing software. On some projects I can't use TDD because interfaces introduce VTBL operation into the code. For me this is a serious issue.
I've always used C++ interfaces i.e., classes with all pure virtual functions for TDD, especially when implementing a design patterns like Factory.
I'm proposing a compiler option that will turn a virtual call through an interface, to a direct call on the object. For example,
interface* i = Factory::Create();
i->someVirtualFunc();
In cases where single inheritance is used i->someVirtualFunc() would be optimized to a direct call on the object without any VTBL operation.
This way the TDD code can use the standard VTBL operations, and in production builds a flag can be set to optimize it away. I can't do this myself without mentioning the concrete type created by the factory but the compiler can make the optimization.
--James S.
Test-driven development (TDD) is my de facto standard for writing software. On some projects I can't use TDD because interfaces introduce VTBL operation into the code. For me this is a serious issue.
I've always used C++ interfaces i.e., classes with all pure virtual functions for TDD, especially when implementing a design patterns like Factory.
I'm proposing a compiler option that will turn a virtual call through an interface, to a direct call on the object. For example,
interface* i = Factory::Create();
i->someVirtualFunc();
In cases where single inheritance is used i->someVirtualFunc() would be optimized to a direct call on the object without any VTBL operation.
This way the TDD code can use the standard VTBL operations, and in production builds a flag can be set to optimize it away. I can't do this myself without mentioning the concrete type created by the factory but the compiler can make the optimization.
--James S.
Received on 2023-11-10 01:22:04