version: multiple conditions

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 30 09:19:53 PDT 2015


On Tuesday, 30 June 2015 at 15:55:49 UTC, bitwise wrote:
> On Tuesday, 30 June 2015 at 02:30:44 UTC, Walter Bright wrote:
>>
>> I don't believe a macro processor is necessary to write 
>> systems code, nor do I believe version expressions are, either.
>
> Waiiit a minute...reading this again, it seems you are talking 
> about writing code for a single system.
>
> In that case, yea, I suppose you can get by without versions. 
> The market in multi-platform mobile apps is not something that 
> should be ignored though.

You need version blocks to distinguish between platforms (be it 
OSes or architectures or whatever), but code like that should be 
wrapped at a fairly low level, and most code shouldn't have 
anything like that in it. e.g. druntime has tons of version 
blocks, whereas Phobos has relatively few. Certainly, in general, 
if you're using complex expressions for versions, you should 
probably be rethinking how you're doing your code. I've dealt 
with code before that shared code across multiple products and 
altered its behavior via ifdefs, and it was a _disaster_. It 
would have been _far_ cleaner to just separate it out via 
libraries and section off the system-specific code such that it 
was contained and generally small. Once in a while, being able to 
&& or || version identifiers like linux and FreeBSD would be 
nice, but on the whole, I have to agree that if you're doing much 
of that, it's just a recipe for disaster. I suppose that the 
problem is that it's just useful enough in some cases that it's 
annoying not to have it, but if we _did_ have it, it would be 
abused like there's no tomorrow.

- Jonathan M Davis


More information about the Digitalmars-d mailing list