Cross module version specs
James Miller
james at aatch.net
Thu Apr 26 15:40:45 PDT 2012
On Thursday, 26 April 2012 at 12:37:44 UTC, Steven Schveighoffer
wrote:
> On Thu, 26 Apr 2012 06:32:58 -0400, James Miller
> <james at aatch.net> wrote:
>
>> On Thursday, 26 April 2012 at 10:20:37 UTC, Jonathan M Davis
>> wrote:
>>> On Thursday, April 26, 2012 12:09:19 James Miller wrote:
>>>> which pretty much makes them completely useless unless
>>>> you only use the built-in versions.
>>>
>>> That's not true at all. It just means that versions are
>>> either useful for
>>> something within a module or they're intended for your
>>> program as a whole and
>>> passed on the command line (e.g. StdDdoc is used by Phobos,
>>> and it's not
>>> standard at all; the makefile adds it to the list of compiler
>>> flags). But yes,
>>> it's true that if you want to define a version in one module
>>> which affects
>>> another, you can't do it.
>>
>> Is there any reason for that limitation? Seems like an
>> arbitrary limit to me.
>>
>> The library I am binding to uses ifdefs to let the compiler
>> see the appropriate declarations in the header files. It would
>> be nice in general for D to be able to mimic that capability,
>> as it means you can have a "configuration" file with a list of
>> specs that can be generated at build-time by something like
>> autoconf.
>
> No, it would not be nice, it would be horrible. C's
> preprocessor is one of the main reasons I sought out something
> like D. The fact that you can include files in a different
> order and get a completely different result is not conducive to
> understanding code or keeping code sane.
>
> The correct thing to use for something like this is enums and
> static ifs. They work because enums are fully qualified within
> the module they are defined, and you can't define and use the
> same unqualified enums in multiple places.
>
[snip]
>
> These kinds of decoupled effects are what kills me when I ever
> read a heavily #ifdef'd header file.
>
> versions should be defined for the *entire program*, not just
> for certain files. And if they are defined just for certain
> files, define them in the file itself.
>
> -Steve
I didn't think about it like that, thanks. I'm planning on just
using enums and static ifs in this case now, since it certainly
makes more sense and I can achieve the same effect.
Thanks all
--
James Miller
More information about the Digitalmars-d
mailing list