No need for version expression is a lie
Don
prosthetictelevisions at teletubby.medical.com
Tue Aug 22 10:24:34 UTC 2023
On Monday, 21 August 2023 at 19:27:57 UTC, Walter Bright wrote:
> On 8/21/2023 11:46 AM, Basile B. wrote:
>> However that approach was used. It really looks like an
>> alternative to a version OrOr. There are plenty of other
>> examples in drutime sources.
>
> Druntime was written by many people, and does not exhibit
> consistent best practices.
>
>> Sure at some point there is also the problem of the unix
>> standards...Every distribution can choose its own value for
>> the flag of this func or that one...which creates complexity
>> in C `define`s, but should not in D. There is a problem that
>> is not solved.
>
> I've dealt with enough professional C .h files to conclude that
> #ifdef algebra is the worst solution. This includes the ones I
> have written.
>
> The objectives of minimizing keystrokes and maximizing clarity
> are only rarely aligned.
>
> I understand that many of D's design decisions are out of step
> with conventional wisdom. They aren't the result of reading
> about best practices, but instead decades of living with those
> practices.
There are multiple problems with the #ifdef algebra.
The prohibition against boolean expressions in version
conditionals is a good one and fixes some of the problems.
But #ifdef also allows horribly nested conditionals, and D
doesn't stop that.
Also D doesn't deal with versions defined on the command line.
The whole algebra of "defined" vs "undefined" is a sloppy
error-prone concept that is out of place in a statically typed
language. It's like PHP or something.
In that original example, a typical typo would be MICOBLAZE. That
could go undetected for years. A statically typed language should
catch that.
Years ago I proposed that versions should be considered to be
bools in a kind of compile-time only 'version' scope and obey
normal bool rules. You could then allow boolean expressions in
version _declarations_ (not in conditionals).
In the original example you would define something like:
version DEFAULT_MS_ENUMS = MICROBLAZE || SH || ARM_Any ||
IBMZ_Any || IA_64 || M68K || TILE || X86_Any || RISCV_Any ||
SPARC_Any || PPC_Any;
The syntax I suggested was something like:
version <version_identifier> = <version_expression>;
version <version_identifier> = true; // same as the existing
version = <version_identifier>; but this would only be used in
testing I think
version <version_identifier> = extern; // for something defined
on the command line
version <version_identifier> = default; // for a compiler built-in
where <version_expression> is a boolean expression of
<version_identifier> using || and &&.
If additionally you disallowed version declarations and version
statements inside version conditionals, you'd have a
one-definition rule and it would be impossible to create a rat's
nest. (You could still create a rat's nest with static if, but
not with version).
- Don.ghostof
/disappears again into the mist
More information about the Digitalmars-d
mailing list