No need for version expression is a lie
Adam D Ruppe
destructionator at gmail.com
Thu Aug 24 15:30:37 UTC 2023
On Thursday, 24 August 2023 at 04:53:49 UTC, Walter Bright wrote:
> Can you be more specific? I'm curious.
version(unittest) made waves some time ago, making all kinds of
random errors when user code was trying to be tested but still
imported phobos modules.
> For library writers, there are indeed some things to watch out
> for. I recommend using the name of the library as a prefix on
> their version identifiers.
Yeah, that's what I tend to do too, but it is just a convention.
The language probably could have defined versions to be specific
to a module, even if given on the command line.
But name conflicts are one of the smallest problems with them.
When a mismatch on compile and import lead to ABI mismatches are
the worst.
I wrote at greater length about this here:
http://dpldocs.info/this-week-in-d/Blog.Posted_2022_11_14.html#redesign-for-template-emission-woes
> Phobos has some head-scratchers, like this in std.stdio:
This specific one doesn't seem to make sense, but this pattern
comes up a lot because you might want to use a specific
implementation from multiple triggers.
Easy to imagine there might be a CRuntime_DigitalMars and a
CRuntime_DigitalMars64, for example, different predefined
versions that share the implementation of this portion. But other
parts of the module might branch differently on
CRuntime_DigitalMars vs DM64, so you couldn't just find/replace
all if you decided to add the other one.
So the author there is probably doing this to try to future-proof
the code with some extra semantic tagging in case some other
definition is added. I've done this a few times myself.
It actually isn't all bad, but it can get ugly when someone
specifies `-version=DIGITAL_MARS_STDIO` on the command line when
building against Microsoft C runtime... then what happens?
Or when someone again tries to figure proof and puts `else static
assert(0)` at the end, making incremental porting impossible.
(which i also wrote about in the last year:
http://dpldocs.info/this-week-in-d/Blog.Posted_2023_02_20.html#static-assert-patterns-arguably-harmful-for-porting )
C's ifdef is a big mess.
D's version is a different big mess, but still a mess.
More information about the Digitalmars-d
mailing list