Prof. A Olowofoyeku (The African Chief) wrote:
b)
Using some magic that looks up the dynamic method index in some internal table to do the call.
The disadvantages of b) are that it requires more compiler magic, and that it might be type-unsafe (if the method is looked up at runtime, there's no way for the compiler to check the parameter list -- unless all dynamic methods are required to have the same parameters).
In BP OWL and Delphi VCL code, they all seemed to involve a parameter "(Var Message : TMessage)" - but may well be a result of the message dispatching protocols involved in the respective OOP frameworks. If you tried this in OWL without having that parameter, you always got a GPF (aka segfault, stackdump, or whatever corresponds on other systems). The GPF may well be a sign of the type- unsafeness that you talk about (i.e., it is up to the programmer to get it right).
It seems so.
The only advantages I can see are that it might save a few bytes in memory (which is most likely a non-issue today and probably it was even back then), and that it may have been faster at runtime than a `case' statement in BP. However, GPC/GCC optimizes `case' much better, using jump tables when useful, so that's probably no issue, either.
Then, it's a little effort to write the `case' statement, but that's mostly a one-time job I think (and can probably be added to existing BP code locally), so I'd suggest this.
Unfortunately, my experience with building an OOP framework showed that it is far more involved than a simple case statement. I basically had to invent my own message dispatching mechanisms. These involved case statements, but that was only the end of the process. It may well be however that, for normal programming, this wouldn't be the case, and it would just be a matter of a simple case statement.
It might not be all that's required for an OOP framework, but I can't see the dynamic methods doing much more than a `case' statement. After all, it's only one integer value ...
Maybe they use other "magic", hidden in the compiler or (I hope) the libraries, independent of dynamic methods.
Be that as it may, simply supporting the syntax would be good enough, and I would be happy with whatever direction you choose to go.
For now I'll just ignore the index. If it ever becomes necessary to use it, one will have to think about how to make it available ...
Frank