Other language features you'd want in D
Alexander Panek
alexander.panek at brainsware.org
Sat Feb 23 10:39:37 PST 2008
Robert Fraser wrote:
> Constant initialization can already be paired with declaration for
> non-class types:
>
> const(int) HTTP_PORT = 80;
>
> But it can't be for class types at global scope:
>
> const(Port) HTTP_PORT = new Port(80);
>
>
> How is making it valid for (primitives, arrays, structs, anything with a
> constant initializer) but not for classes "keeping initialization in one
> place"?
You're having a compile-time literal vs. a runtime object here. That's
kinda a big difference, you know? I wouldn't want to have my runtime
object initialization to be somewhere in class declaration scope. Kinda
hard to measure the performance then.
Oh, besides... this wouldn't even be in static constructor, but rather
the normal constructor.
class A {
Port httpPort;
this (int port = 80) {
httpPort = new Port(port);
}
}
I'd like to keep the "verbosity" of initializing class members at
runtime as-is.
More information about the Digitalmars-d
mailing list