OpenBSD port of dmd?

Daniel Murphy yebblies at nospamgmail.com
Fri Mar 16 18:16:29 PDT 2012


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:jk0naq$257e$1 at digitalmars.com...
>
> But why duplicate doItSlowWay(); which may be an arbitrarily long 
> sequence?

If duplicating that block is a problem, there are other ways to do it.

version(ThisOS)
{
   version = FastWayA;
}
else version(ThatOS)
{
   version = FastWayB;
}
else version(SomeOS)
{
   version = SlowWay;
}
else version(OtherOS)
{
   version = SlowWay;
}
else
   static assert(0, "OS not implemented");

version(FastWayA)
{
...
}
else version (FastWayB)
{
...
}
else version (SlowWay)
{
...
}


>
> This seems to accomplish little more than "well I didn't use else".
>
> Again: what exactly is wrong with specialization?
>

The advantage is, that when you write the code, you have _no idea_ what 
platform/os it might need to run on in the future.  You _cannot_ know which 
version is most appropriate for _all_ new platforms, or even if any of them 
will work at all.  The only time to make this decision is when implementing 
support for a specific platform, and this pattern forces you to consider 
each place where platform specific behaviour is required.  When doing things 
like this, 100 false positives are much faster to fix than a single false 
negative causing wrong code/corruption. 




More information about the Digitalmars-d mailing list