Why version() ?

Tim M a at b.com
Tue Feb 10 15:58:12 PST 2009


On Wed, 11 Feb 2009 12:16:16 +1300, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> Nick Sabalausky wrote:
>> This strikes me as throwing away the baby with the bathwater. If your  
>> code starts degenerating towards a versioning rat's nest, then the  
>> solution is to take a moment and refactor it into a larger granularity,  
>> not to throw away features that are useful in moderation.
>
> True, but that never, ever happens. It's always "I can get my few  
> additions to this rat's nest in and just get it working, and worry about  
> proper abstraction later."
>
>>> 1. Why not version(!feature) ?
>>>
>>> Because cognitive studies show that people just don't see the negation.
>>  Isn't that moreso a case against the ! operator in general? I don't  
>> see how "if(!blah)" is any less susceptible to overlooking the ! than  
>> "version(!blah)".
>
> Yes, you're right, it's both a minor and an inconsistent point, despite  
> it being right <g>.
>
>
>>> Secondly, when you see things like:
>>>
>>>     version (!linux) { ... }
>>>
>>> they're almost always wrong. Versions should be positive things,  
>>> because a version is something that is being build - one doesn't craft  
>>> a makefile to build a notLinux.
>>  True, we don't build to a NotLinux, but we do however build to  
>> "everything except platform X".
>
> We do, and they're always wrong. I always find when doing that and  
> porting to another machine that those #if !linux must be reengineered. I  
> have switched entirely over to:
>
> #if Windows
>     ...
> #elif linux
>     ...
> #elif __APPLE__
>     ...
> #else
>     assert(0); // fix when adding a new platform
> #endif
>
> because otherwise I *miss* sections that need updating when porting to a  
> new platform, and have a bug that needs tracking down.
>
> The point is, when writing portable code, especially code that will be  
> ported by others, you have *no idea* what platforms will fall into the  
> "notLinux" section and what peculiarities those platforms might have. It  
> works much better to have the compiler ding me when it encounters  
> platform specific code that doesn't have a section for the platform I'm  
> compiling for.
>
>> And I don't see how a "LinuxOrMac" (or worse yet, a  
>> "LinuxOr_MacAndSomeOtherCharacteristic_") is any more or less of a  
>> realistic platform than a "NotLinux".
>
> Based on my experience porting code, LinuxOrMac is a far better solution  
> (i.e. faster to code, faster to port, fewer bugs) than notWindows.
>
>
>> Also, you didn't respond to the concerns about typos in a version  
>> identifier. Can we assume you agree that's a problem?
>
> It's a problem without a solution unless you propose adding some sort of  
> declaration syntax for all the version identifiers.

It would be nice if version just evaluated to a bool of true if the  
version is defined or false otherwise and you have to use it in static if  
statements, drop the old syntax. This would be very consistent, powerfull  
and if that is considered bad style then it shouldn't have to be used in  
the same way goto statements are rarely used yet they still exist.



More information about the Digitalmars-d mailing list