Predefined Versions for Apple Operating Systems
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sun Jun 22 00:44:42 UTC 2025
On Saturday, June 21, 2025 2:24:34 PM Mountain Daylight Time Walter Bright via Digitalmars-d wrote:
> Currently, the following predefined versions exist for Apple operating systems:
>
> OSX iOS TVOS WatchOS VisionOS
>
> When I look at druntime source code, I see things like:
>
> ```d
> version (OSX)
> version = Darwin;
> else version (iOS)
> version = Darwin;
> else version (TVOS)
> version = Darwin;
> else version (WatchOS)
> version = Darwin;
> ```
> and:
> ```d
>
> ```d
> version (OSX) {}
> else version (iOS) {}
> else version (TVOS) {}
> else version (WatchOS) {}
> else:
> ```
> appearing ad nauseam.
>
> (note the conspicuous absence of VisionOS appearing in druntime)
>
> I propose, like Windows encompassing Win32 and Win64, that __APPLE__ encompass
> OSX, iOS, TVOS, WatchOS, and VisionOS. __APPLE__ is already standardized in C
> headers for that purpose.
>
> The use of "darwin" or "Darwin" appears to be quite obsolete.
>
> This will clean up a lot of version algebra in the druntime files.
At the end of the day, I don't care enough to fight over this issue, but
IMHO, the fact that the version identifiers try to follow C #defines has
been a cause of bugs and that it was a mistake to ever try that over simply
using our own consistent naming scheme - in particular, the fact that linux
is lowercase when the other OSes typically start with an uppercase later has
been problematic. And since you don't get an error if you mistype the
identifier (at least not if having code not versioned in doesn't create a
compiler error), it's often easy to miss the mistake (especially with
bindings that don't always have tests associated with them).
So, personally, I think that naming it `__APPLE__` is a bad idea and that if
we want something like that, it should just be something like Apple or
AppleOS.
Though honestly, if we were redoing all version identifiers, I'd be tempted
to argue that they should just all be required to be lowercase so that we
had fewer bugs due to typos and less confusion over casing. It's not a
problem with identifiers in general, because you get errors if you get those
wrong, but the fact that we can't do that with version identifiers makes the
inconsistencies in their names error-prone.
On the other hand, if we were redoing them, maybe it would be better to just
make them all of the predefined ones start with `__` so that any that start
with `__` but aren't known are an error, significantly reducing the bugs
related to mistyping version identifers - not that that would entirely fix
the problem, since someone could still forget a `_` and make it look like a
user-defined one (and of course, we can't fix the problem with user-defined
ones unless we do something like require that a list of all valid version
identifiers be provided somehow).
In any case, the version identifiers are already a bug-prone mess, so maybe
it doesn't matter if we use `__APPLE__` instead of something like Apple or
AppleOS, but the naming inconsistencies that we already have have been
causing bugs for years when a more consistent naming scheme would have at
least reduced the problem.
As for Darwin or whether we need `__APPLE__` (or whatever we call it) as a
replacement, well, I'm not familiar enough with Apple's OSes to weigh in on
that.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list