Final by default?

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 14 07:26:23 PDT 2014


On Fri, 14 Mar 2014 10:11:25 -0400, Ethan <gooberman at gmail.com> wrote:

> On Friday, 14 March 2014 at 14:02:06 UTC, Steven Schveighoffer
> wrote:
>>
>> And for that point, your demonstration has failed :)
>
> It's an extraordinarily simple use case, but it is still quite a
> common pattern in C++ defines, ie:
>
> #ifdef _DEBUG
> #define FEATUREA
> #define FEATUREB
> #define FEATUREC
> #else
> #define FEATUREB
> #define FEATUREC
> #endif
>
> #ifdef FEATUREB
> ...
> #endif

No, not really, there was no else in the version. It's when you have two  
different versions that may trigger the same definition.

#if defined(MODEA) || defined(MODEB)
#define FEATUREA
#define FEATUREB
#endif

In D, this is:

version(MODEA) version = USEFEATUREAANDB;
version(MODEB) version = USEFEATUREAANDB;

...

version(USEFEATUREAANDB) // imagine reading this first, and wondering what  
causes it to compile.
{
    version = FEATUREA;
    version = FEATUREB;
}

It's the equivalent of this in C:

#ifdef MODEA
#define USEFEATUREAANDB
#endif
#ifdef MODEB
#define USEFEATUREAANDB
#endif

...

#ifdef USEFEATUREAANDB
#define FEATUREA
#define FEATUREB
#endif

Yes, there are real world examples where the lack of logical or makes  
things difficult to read. It's not all about versioning based on OS or  
boolean flags.

-Steve


More information about the Digitalmars-d mailing list