Walter: extend existing classes with new methods?
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Mon Sep 4 15:11:19 PDT 2006
Marcio wrote:
>
> If I understood your argument correctly, you are saying that you
> can't have a compiler compile code for a class if the source is split
> across multiple source files? Because, after all, that's all we're
> talking about here. Class foo has some code in foo.d, some code in bar.d
> (it added methods to foo) and so on.
>
> Well, if we are going to use that argument, we might as well move back
> in time to the old days of Turbo Pascal 3.0. If you wanted to use a
> procedure Foo, it had to have already appeared in the source. So, for
> cases like recursive descendent parsers or recursive tree traversal you
> had to declare the function, and later have it appear again, with the
> body itself. This allowed you to have mutually recursive procedures.
> This was because the compiler couldn't do any look-ahead or 2-pass. Way
> to go, put the burden on the developer because of a compiler limitation.
> Fina when you have 64KB of RAM like the MSX I guess...
>
> I think compilers should serve developers, not the other way around.
>
> By the way, the reason Java source has so many "instanceof" is because
> it doesn't allow this type of extension. If the language allows
> extensions, you can easily code things with polymorphism by adding say
> isFoo to Object (return false) and overriding it in your Foo class
> (return true). No need for instanceof. You want to know if the object
> isFoo? Damn, just ask it. Use OO. This is a very common pattern of
> coding in systems like Smalltalk.
Now I know I misunderstood you. Extension methods I was thinking of are
like the ones in C#3.0 and they can only be static. I don't see how
adding a nonstatic method should work. Static extension methods might
not be as useful as nonstatic ones but it can be a nice feature.
More information about the Digitalmars-d
mailing list