Conditional compilation inside asm and enum declarations
Walter Bright
newshound1 at digitalmars.com
Tue Jul 14 14:00:34 PDT 2009
Andrei Alexandrescu wrote:
>> 1. It's pretty clear what is happening for each system.
> Not clear to me. It's happened to me more than once to fix a function
> without knowing that it's version()ed (your fault: you didn't indent it)
> and that there's a corresponding Windows function some miles away.
That stuff wasn't in personality modules :-)
> To me it's much clearer to have all specializations of a given piece of
> functionality close to one another. They'd naturally tend to converge,
> not diverge.
That works fine initially. Things tend to go awry after a while, though.
Take a look at the optlink source. I'm sure it didn't start out that way
- the convoluted versioning logic was added layer by layer over many years.
If you find large swaths of logic are being duplicated in personality
modules, that suggests that the wrong level of abstraction is being used.
One of the reasons the FreeBSD port went much faster is I did some
refactoring of the abstractions when I did the OSX port.
>> 4. Porting to a new platform is easier as you've got a list of
>> personality modules that need to be created, rather than version
>> statements threaded through the file contents.
>
> No. This is where your point gets destroyed. Unittests should dictate
> what must be done for porting to a new platform. Your approach forces
> either duplicate unittests, or collector files that add clutter.
While I'm a great believer in unittests, I don't agree they are the
answer to design problems. They are a supplement, not a replacement. I
don't think we're anywhere near 100% Phobos unit test coverage yet.
Clutter is always a problem that needs to be continuously reviewed.
>> 5. The "else" clause in OS version statements tend to be wrong when
>> porting to a new system, meaning that each version has to be gone
>> through manually - overlooking one doesn't always create an obvious
>> error.
>
> I try to avoid else. I want to implement setenv on Windows, I prefix it
> with Windows. I want to implement it on Posix, I prefix it with Posix.
> Then I write one unittest. Then when a new OS comes, setenv won't be
> found so the unittest can't run. Problem solved *much* better.
I agree that the else clause should be avoided for such dependencies,
but the damn things tend to creep back in :-( and I'm back to manually
grepping for versions and ticking them off one by one.
I've done the (initial) port to Linux, I've done the ports to OSX, and
FreeBSD. It was easier to port the personality modules than the version
statements, especially when they went beyond the trivial. It's been
easier to do the same with the compiler source code with the personality
modules, too. I've had a very positive experience with it.
More information about the Digitalmars-d
mailing list