On 2009-02-03 02:15:16 -0500, "Nick Sabalausky" <a...@a.a> said:
"Nick Sabalausky" <a...@a.a> wrote in message
news:gm8pul$1ee...@digitalmars.com...
I had been slowly coming around to the idea of having that universal
function syntax instead of C#-style explicit extension methods, but maybe
this need for dynamic dispatch is a good reason to prefer explicit
extension methods:
// As in C#, the "this" means backup() is an extension method
void backup(this Node obj, string backupPath)
{
// base impl
}
void backup(this File obj, string backupPath)
{
copy(obj.path, backupPath ~ "/" ~ obj.name);
}
void backup(this Directory obj, string backupPath)
{
foreach(child; children)
child.backup(backupPath ~ "/" ~ obj.name);
}
I'm not exactly sure what C# does in this case, but what I'm proposing
here is that this could (somehow) cause dynamic dispatch to be used.
Out of curiosity, I just did a little test on this in C#. Apperently it
doesn't do any dynamic dispatch on this, it just calls the extension method
overload for whatever the static type is.
Great. :-) An area where we could surpass C# by just making things work
the way they should. Although I'm somewhat doubtful we'll see Walter
going away from the simple C++-like vtable design needed for
implementing this.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/