DMD 1.039 and 2.023 releases

bearophile bearophileHUGS at lycos.com
Thu Jan 8 10:03:40 PST 2009


Bill Baxter:
> To me it's hard to see those variable declarations as being anything
> other than scoped to the blocks they're in.
> So all I'm saying is if we could have some different delimiters for
> non-scope blocks then it might be nice, and make it easier to see when
> scopes are ending and when they are not.

*Now* I understand, and I see your point.
It's the usual problem: ASCII doesn't have enough ways to represent containers and delimiters :-)

So if this is your original code (I have improved your indentations and improved readability a little):

void doSomething(T)(int i) {
    if (i == 0) {
        static if (is(T == A)) {
            A.SomeAlias x;
        } else static if(is(T == B)) {
            B.SubType x;
        } else {
            T x;
        }
        
        x = ... whatever
   }
   else
        int y = x;
}


This can be the new version following your idea:

void doSomething(T)(int i) {
    if (i == 0) {
        static if (is(T == A)) ::
            A.SomeAlias x;
        :: else static if(is(T == B)) ::
            B.SubType x;
        :: else ::
            T x;
        ::
        
        x = ... whatever
   }
   else
        int y = x;
}


But the problem is that :: don't have a head and tail, so the code is even less easy to read.

This version uses (* ... *), used in Pascal to denote comments:

void doSomething(T)(int i) {
    if (i == 0) {
        static if (is(T == A)) (*
            A.SomeAlias x;
        *) else static if(is(T == B)) (*
            B.SubType x;
        *) else (*
            T x;
        *)
        
        x = ... whatever
   }
   else
        int y = x;
}


I don't like that too, even if it's a bit better than the version with ::. 

Two other possibilities:

void doSomething(T)(int i) {
    if (i == 0) {
        static if (is(T == A)) {|
            A.SomeAlias x;
        |} else static if(is(T == B)) {|
            B.SubType x;
        |} else {|
            T x;
        |}
        
        x = ... whatever
   }
   else
        int y = x;
}


void doSomething(T)(int i) {
    if (i == 0) {
        static if (is(T == A)) {#
            A.SomeAlias x;
        #} else static if(is(T == B)) {#
            B.SubType x;
        #} else {#
            T x;
        #}
        
        x = ... whatever
   }
   else
        int y = x;
}

I don't think lot of people will appreciate those.
So the lack of different block delimiters may make this problem have no better solution.

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list