Other language features you'd want in D
Robert Fraser
fraserofthenight at gmail.com
Sat Feb 23 15:19:59 PST 2008
Alexander Panek wrote:
> 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.
You don't need a class for that, as you probably know. What I want is for:
const(Port) HTTP_PORT = new Port(80);
to be equivalent to:
Port HTTP_PORT;
static this() { HTTP_PORT = new Port(80); }
except, you know, allowing the const in there somewhere.
More information about the Digitalmars-d
mailing list