Consider two recurrent methods, late hours, complex code. In short, those two functions look like this:
void foo(int x)
{
... foo(x);
}
void bar(int x)
{
... foo(x); // oops, I meant "bar"
}
There are many times I wished (and I still wish) to have some symbolic call like "self", so I could rewrite it like this:
void foo(int x)
{
... self(x);
}
void bar(int x)
{
... self(x); // great! this is what i meant --> bar
}
So far th开发者_C百科e only hack I can think of, would be to write general function "self" which would on call check stack, get the caller, and call it. However it would not be possible to use it with inheritance:
void inherited(int x)
{
base.self(x);
}
Thank you very much for your comments/ideas/etc :-)
Pay more attention when writing code? I don't quite understand why you want it but maybe I'm missing something.
In short, I don't think you can do it without reflection and at that point it would be overkill.
Use F# ;)
(which requires functions are marked as rec
if they recurse within themselves, and you have to "and
" mutually recursive functions together - making your mistakes a compiler error.)
精彩评论