The Next Mainstream Programming Language: A Game Developers Perspective
Søren J. Løvborg
web at kwi.dk
Fri Aug 25 10:04:41 PDT 2006
This presentation seems familiar... :)
One interesting point, is the need to specify ranges of valid numbers.
Pascal had decent support for this, allowing one to define integer types
constrained to a given range:
type MyNumber : 1..15;
D could use something like this, though I'm not sure what to make of the
syntax.
alias 1..15 MyNumber; // allows implicit conversion to (but not from) int.
typedef 1..15 MyNumber; // only allows explicit conversion.
One could imagine this extended to dynamic ranges:
void foo(int i, 0..i j)
But then again, maybe not.
> Software Frameworks The Problem: Users of a framework want to extend the
> functionality
> of the framework's base classes!
> The workarounds:
> - Modify the source ... and modify it again with each new version
> - Add references to payload classes, and dynamically cast them at
> runtime to the appropriate types. - These are all error-prone: Can the
> compiler help us here?
This is a problem I've only seen handled in the pretty obscure language
TADS, which had a "modify" keyword, which allowed user code to replace
entire methods of library classes, as well as add methods. Unlike the
traditional approach -- overriding the methods in a subclass -- this
affected all instances of the given class, also those instantiated in
library code.
class LibraryClass
{
void doStuff() { printf("foo\n"); }
}
modify LibraryClass
{
void doStuff() { printf("bar\n"); }
void entirelyNewFunction() { }
}
This was implemented by making an anonymous subclass of the LibraryClass,
and then having the "LibraryClass" symbol refer to the subclass instead, and
I guess the same could be done in D by screwing around with the linker and
VMT.
I'm not saying this belongs in D; it's a horrible hack from an OOP
standpoint (handy, though), and the "real" solution would be to design
better libraries, with proper hooks.
Søren J. Løvborg
web at kwi.dk
More information about the Digitalmars-d
mailing list