Final by default?

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 14 07:18:52 PDT 2014


On Thu, 13 Mar 2014 18:43:36 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> On 3/13/2014 3:21 PM, Timon Gehr wrote:
>> On 03/13/2014 02:32 PM, Steven Schveighoffer wrote:
>>>
>>> The one I would really like to see is logical OR. There is no easy way
>>> around this, one must come up with convoluted mechanisms that are much
>>> harder to design, write, and understand than just version(x || y)
>>
>> version(A) version=AorB;
>> version(B) version=AorB;
>> version(AorB){ }
>>
>
> If you're writing things like that, it's still missing the point. The  
> point is not to find workarounds, but to rethink just what feature is  
> being version'd on.

There are some times where AorB is the best description, and the machinery  
to factor out is just unnecessarily verbose.

I'm not denying that in some cases, when each version requires it's own  
unique block (Andrei's is a good example) that avoiding OR expressions  
makes a lot more sense.

But, those are not all cases. For example, if you have 4 different  
versions, and 3 of the blocks are the same in module x:

version(a)
{
    decla;
    declb;
    declc;
}
version(b)
{
    decla;
    declb;
    declc;
}
version(c)
{
    decla;
    declb;
    declc;
}
version(d)
{
    decld;
    decle;
    declf;
}
else
    assert(0, "unsupported version!");

Factoring this out becomes an exercise in treasure-map reading:

version(blahblahblah)
{
    decla;
    declb;
    declc;
}
version(d)
{
    decld;
    decle;
    declf;
}
else
   assert(0, "unsupported version!");

Now, I have to go find blahblahblah. Maybe there's even another factoring,  
and blahblahblah is defined by another intermediate version.

Maybe in another block, I have to use yaddayaddayadda, because only a and  
b use a common block and c is different.

Granted, I can invent names for these that make sense, and in some cases  
(like version(posix) or version(unixen) or something) it makes a lot of  
sense that anything which supports them will go into that version. I get  
that.

But when I'm looking at something like blahblahblah, and wondering if it's  
compiled with version(a), I have to go on a hunt. Why not just:

version(a || b || c)

In fact, it probably is a good idea to do:

version(blahblahblah) // a || b || c

to be clearer...

Note that it's already in your best interest to factor a || b || c into  
another identifier, instead of having to repeat that over and over again.  
But sometimes, it's just unnecessarily verbose hoops you have to jump  
through when reading or writing versioned code.

Also note that many many times, a, b, and c are mutually exclusive. So  
there will only be OR clauses for those, never AND. The code is readable  
and straightforward with boolean operators, convoluted and verbose without.

In any case, I don't expect any movement on this. Just had to rant ;)

-Steve


More information about the Digitalmars-d mailing list