On Sat, 17 Jan 2009 06:17:57 +0300, Daniel Keep <daniel.keep.li...@gmail.com> 
wrote:



Bill Baxter wrote:
[snip]
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.


I kinda like that, actually, but I doubt it'll be very popular around here.

--bb

The '#' has a nice connotation for anyone who's used to C/C++, given
that those statements are handled at "compile time."  The problem, of
course, is that they're really nothing like C preprocessor statements.
They have a different syntax, and completely different capabilities.
What's more, you can't mix them across statements/expressions, so I
suspect it would just cause more confusion.

Additionally, there's this:

   #endif

Unless you plan on moving all control structures to BASIC/pascal style,
I don't think it's wise to start mixing them all over the place.

I do like the idea of a "scopeless block" syntax in theory, though it's
not something that's really been an issue for me.

  -- Daniel

Well, syntax could be different:

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

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

But I don't see how '#' at the beginning is useful.

Reply via email to