version(number) is completely useless

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 20 02:44:28 UTC 2022


On 7/19/22 10:10 PM, Andrey Zherikov wrote:
> On Wednesday, 20 July 2022 at 01:34:00 UTC, Steven Schveighoffer wrote:
>> On 7/19/22 9:22 PM, Andrey Zherikov wrote:
>>> I actually have a question since this topic is brought up:
>>> What is conceptual difference between `version(FOO)` and `static 
>>> if(FOO)`? I see `version` is a very limited comparing to `static if` 
>>> - the former checks for "boolean" result (whether an ID is defined) 
>>> while the latter evaluates condition expression.
>>
>> version is specifically a replacement for #defines as in C. They are 
>> specified mostly on the command line.
> 
> It's not a full replacement because it doesn't support `-DSOME_DEFINE=5` 
> or `-DANOTHER_DEFINE="some string"`.

Yes, and actually, this is not something I miss terribly. One place 
where I do miss it is communicating something like git version 
information to the compiler. The only way to do this is to pre-build a 
module for it.

>> The thing I miss the most for versions is a `version1 or version2` 
>> mechanism. I doubt we will ever convince Walter this is a good idea.
> 
> I don't think that `version1 or version2` is any different than allowing 
> complete conditional expression.

`version(a) version(b)` accomplishes a && b. But a || b is just a 
complete pain to write.

> 
>> But in any case, we have the numeric versions, which are 100% useless 
>> (because, as you say, they are not scoped to any dependencies), it 
>> would make sense to at least make that feature useful.
> 
> I don't see how raw numbers can be useful. Could you clarify your idea?

The proposal here (I think) is that if you define version `MyLibrary.5` 
then `version(MyLibrary.4)` or `version(MyLibrary.1)` all are enabled.

What the current system does is worthless, because `version(5)` has no 
meaning. If we scope the numbers to be within a specific project, then 
that project has the ability to define what those things mean, and you 
can just define one version on the command line.

-Steve


More information about the Digitalmars-d mailing list