Smooth transition to D2 for Tango users?

Sean Kelly sean at invisibleduck.org
Mon Sep 22 21:35:53 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;
> 
>> // D1
>> const x = "hello";
>>
>> // D2
>> enum x = "hello";

Good point.

>> 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])

The reason I brought this up is because multiprogramming can potentially 
avoid locking when using invariant data (const in D1), but it can't when 
using const data.  So a diligent programmer would have to replace all 
uses of "const" in D1 with "invariant" in D2.  But it would be easy 
enough to do with with a template as you've suggested above.

>> 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.

That'd be pretty nifty.


Sean



More information about the Digitalmars-d mailing list