OpenBSD port of dmd?

Alix Pexton alix.DOT.pexton at gmail.DOT.com
Sat Mar 17 17:10:19 PDT 2012


On 17/03/2012 16:43, Andrei Alexandrescu wrote:
> On 3/17/12 9:10 AM, Sean Kelly wrote:
>> Pretty much. I'd expect to see:
>>
>> version (linux) {
>> // optimized impl
>> } else version (OSX) {
>> version = UseDefault;
>> } else {
>> static assert(false, "unknown platform");
>> }
>> version (UseDefault) {
>> ...
>> }
>
> Taking this to its logical conclusion means that _all_ code that is
> currently unguarded must be guarded by version (UseDefault).
>
> Andrei
>
>

Firstly, I don't think the name "UseDefault" was well chosen for this 
example. I don't think its meant to be a catch all for every occasion 
when version statements are used. Perhaps "NoFeatureXyzIntrinsic" would 
be clearer.

Secondly, if every line of D code is potentially platform-specific 
and/or inherently inefficient unless optimised with some case specific 
intrinsic, then there must be some glaring problems with the 
abstractions that the language provides.

I will also reiterate that I believe that there are 2 different cases 
being considered together here.
_Compatibility_, where asserting in the else of a version statement is 
the best course of action.
_Opportunistic-Optimisation_, where providing a default case in the else 
as a fall back is quite sensible.

The scenario which applies can often be easily deduced, it is my 
experience that optimisations are "versioned-in" while incompatibilities 
are "versioned-out".
i.e. Adding a platform specific optimisation is "versioning-in", and the 
prior platform agnostic code becomes the default. Proofing a platform 
specific module is "versioning-out" removing inapplicable code and 
leaving a note for the maintainer that other platforms will require 
their own implementation.

In the cases where the programmer does not have enough knowledge to know 
which scenario applies (perhaps not knowing if a particular intrinsic 
has compatible implementations across all platforms), I find it hard to 
find any argument in favour of providing a default action that may have 
unknown effects on another system.

A...


More information about the Digitalmars-d mailing list