Why version() ?

Walter Bright newshound1 at digitalmars.com
Tue Feb 10 14:01:29 PST 2009


Derek Parnell wrote:
> On Tue, 10 Feb 2009 13:14:24 -0800, Walter Bright wrote:
> 
>> The version statement is designed to be inflexible. It's designed to 
>> encourage abstracting and modularizing version differences, rather than 
>> encouraging line-by-line differences.
> 
> I understand and support this view. However, it creates a new problem; code
> duplication. Is it possible to provide some syntax or technique to avoid
> having to cut&paste /small/ runs of code lines. Larger sections of code can
> be separated into functions or modules, but it because problematic when
> dealing with small sections (a few lines) of code. The overheads of
> function calling can be an issue.

I don't think that duplicating a small run of code is a problem. If it's 
larger than a small run, it can be abstracted into a function (the 
overhead is not an issue, as small functions are inlined).



>> 5. Why can't one 'version out' syntax that is not recognized by the 
>> compiler?
>>
>> The problem is that supporting this requires semantic analysis in order 
>> to successfully lex and parse the source code. Breaking this will make 
>> the lexing and parsing an order of magnitude harder for third party 
>> tools to do.
> 
> Agreed, this is a problem. How can it be solved?
> 
> The problem is often found when supporting V1 and V2 code in the same
> source file. The string mixin trick is NOT, repeat NOT, a satisfactory
> solution.

I agree that the mixin trick is horrific.

> Duplicating (nearly all of a) source file is NOT, repeat NOT, a
> satisfatory solution.

I'm not insensitive to this as I do it myself in maintaining Phobos. It 
is a problem, but not a huge one. I find that the meld utility (on 
linux) makes this chore a snap.



More information about the Digitalmars-d mailing list