bearophile wrote:
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

in C# they use the same syntax as the c pre-processor for conditional compilation and such even though C# doesn't have a pre-processor and the syntax is interpreted by the compiler. the above would be something like:

 void doSomething(T)(int i) {
      if (i == 0) {
          #if (is(T == A))
              A.SomeAlias x;
          #elif (is(T == B))
              B.SubType x;
          #else
              T x;
          #endif

          x = ... whatever
     }
     else
          int y = x;
 }

D can always revert to this kind of syntax for compile time code.

Reply via email to