Smooth transition to D2 for Tango users?

Jason House jason.james.house at gmail.com
Tue Sep 23 14:51:05 PDT 2008


Sergey Gromov Wrote:

> Sean Kelly <sean at invisibleduck.org> wrote:
> > Sergey Gromov wrote:
> > > Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> > >> oops, D1 doesn't support that type of enum ;)
> > > 
> > > I think you've got the idea. The code
> > > 
> > > version (D_Version2)
> > > {
> > >   mixin("some very specific code");
> > > }
> > > 
> > > works in any version of D, current or future.
> > 
> > String mixins don't work directly for everything though.  If you want to 
> > change a return value from non-const to const, for example, you need to 
> > make an alias for it using a versioned string mixin and then use the 
> > alias in the function declaration.  And then there are things like this:
> 
> template Const(T) {
>   version (D_Version2) {
>     alias const(T) Const;
>   } else {
>     alias T Const;
>   }
> }
> 
> then
> 
> Const!(int) bar;
> 
> is just one char more than
> 
> const(int) bar;

This style of solution won't work for function declarations... There's no way to mixin const/invariant/pure function declarations without taking the function body along for the ride. If only we could find a way to make the D1 compiler ignore those extra function attributes.




 


> 
> > // D1
> > const x = "hello";
> > 
> > // D2
> > enum x = "hello";
> > 
> > With string mixins you end up having to duplicate the entire line, and 
> > this can be a disaster if you're trying to maintain large header files 
> > with tons of declarations.
> 
> const keyword can be used to declare manifest constants in D2:
> 
> const x = "foo";
> pragma(msg, typeof(x).stringof);	// invariant(char[3u])
> 
> > Finally, I think the version(D_Version2) idea is backwards.  It should 
> > be version(D_Version1).  The current method isn't forwards-compatible, 
> > so all the code with these version statements in it will break when we 
> > get D version 3.
> 
> I agree here, there's not enough flexibility.  The version identifiers 
> should also have a numeric value, so that you can write:
> 
> version (D_Version, 2)
> {
>   ...
> }
> 
> and the versioned code compiles only if D_Version has value of 2 or 
> greater.




More information about the Digitalmars-d mailing list