Porting D2 code to D1

Bill Baxter dnewsgroup at billbaxter.com
Fri Jul 18 00:07:11 PDT 2008


Ryan Bloomfield wrote:
> Bill Baxter Wrote:
> 
>> Ryan Bloomfield wrote:
>>> Jarrett Billingsley Wrote:
>>>> To be honest, I kind of wish this were the case with version statements all 
>>>> the time. 
>>>>
>>>>
>>>     I disagree. I think it's good for all version blocks to compile under normal circumstances.  If it didn't do that, uncompilable code could creep in.   It would be especially bad if it involves machine-specific code.  Coding between different versions of D is clearly going to be used less then the other intended uses of 'version'.  
>> But it doesn't really solve the problem.  So you have syntactically 
>> correct code.  Yippee.  You still can't say whether it's semantically 
>> valid until you actually compile it.  So it provides protection from 
>> code rot some of the time.  But if you're worried about code rot, 
>> syntactic validity is not enough.  There's no substitute for actually 
>> compiling and testing the code you want to have work.
> 
> I thought about the limitations of syntactic validity when I was writing it.   I suppose I should have included that thought.  I think the following is still an issue:
> 
> Nothing within version blocks can be guaranteed to be syntactically correct for any form of syntax analysis, without semantically determining the actual values set with 'version=...'. 
> 
> This also appears breaks the rule: "a source file can be syntactically analyzed without needing any semantic information"  from the following interview:
> 
> http://www.bitwisemag.com/copy/programming/d/interview/d_programming_language.html
> 
> I may just be rambling on here, does this make sense?

I think I get your gist.  The syntactic validity requirement is not so 
much for catching programming errors as it is for keeping parsing simple 
for tools.  That makes sense, and I think I've actually heard that 
argument before but just forgot about it.

I don't like special cases in general, but maybe an exception can be 
made here.  Version blocks that specify a version of the D language 
would be treated specially.  That is, the D 1 and 2 specs could be 
amended to say that any version matching the pattern "D_Version[0-9]+" 
is special, and the contents of the following block should be ignored by 
a compiler or tool that does not support that version of the language.

--bb



More information about the Digitalmars-d mailing list