Hi!
Thank you for the suggestion! I agree that it will make code more maintainable. And you gave an interesting point on performance - case/switch based solution is indeed expected to be faster than the sequence of if/then.
However, there are two reasons why this code existed for so long in ALGLIB for C++:
1. I was already aware of the fact that C/C++ standard allows jumps into control structures. The fact I am unaware of is the following: how many widely used compilers adhere to this standard in such fine details? Obviously, GCC, MSVC, ICC. But we have several industry users who continue to use many years old compilers for obscure systems... and I afraid that some of these compilers may break.
I know that you and me are right :) but I afraid that something may break even if we are right. And ALGLIB tries to be as portable as possible. If you can add something on this point, I'd be glad to hear it!
2. A bit demotivating is the fact that ALGLIB for C# can not be optimized in the similar way.
Although C# has support for continuations, some fine details are slightly different. Continuations do not match 100% to reverse communication interface. So, utilizing C# native continuations opens the door for potential mismatch between ALGLIB for C++ and ALGLIB for C#. Code which behaves differently in C++ and C# versions. And, unfortunately, C# does not allows us to switch into the middle of the control structure - its switch/case statement is quite limited.
So, even if we fix C++, C# control structures will still be blown apart. It is not the reason to abandon C/C++ improvements - but it is demotivating factor.
|