On Sunday, 18 March 2012 at 18:09:42 UTC, Peter Alexander wrote:
On Saturday, 17 March 2012 at 01:37:49 UTC, Andrei Alexandrescu
wrote:
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.
Oh yes I do. Often I know every platform has e.g. getchar() so
I can use it. That will definitely work for everyone. Then, if
I get to optimize things for particular platforms, great. This
is the case for many artifacts.
version(PlatformX)
{
return superfastgetchar();
}
else
{
return getchar();
}
Later on, we add support for PlatformY, which also supports
superfastgetchar(). If you write code as above then no one will
notice. It will just happily use getchar() and suffer because
of it. If you static assert on new platforms then it forces you
to look at the code for each new platform added and think about
what version would be best.
As Walter said, you can't know what version will be most
appropriate for all new platforms.
It should be possible to eat the cake and still have it... even
if warnings normally are frowned upon(with good reason), using
warnings for this would allow the benefits from both "camps"...
It would allow a painless "prototype porting" for new operating
systems which are similar, yet... even if it does work, at a
later point one would still have to go through all the version
statements and either silencing the warning, or selecting the
optimized path.