I asked about this on github but didn't get a good answer, so I'm asking here. What's with all the repeated OS blocks in druntime?

https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/unistd.d#L945
https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/netinet/in_.d#L974
https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/arpa/inet.d#L201

It seems like pointless repetition and there are many more examples of this, as I keep running into it when adding bionic/Android support. Martin suggested that it would be useful to have a default case that asserts for an unsupported OS, but many of these blocks don't have that either.

Why not just declare them once for Posix and then specialize for a particular OS later on when necessary, as seems to have been done in these instances?

https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/sys/stat.d#L954
https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/unistd.d#L95
https://github.com/D-Programming-Language/druntime/blob/master/src/core/sys/posix/signal.d#L425

Note that the last version(Posix) check in core.sys.posix.signal on line 479 is always going to be hit. You could argue that it's worth it just to document that that is the last case we expect to hit, but then the static assert after that is pointless.

As can be seen from these links, druntime is not consistent in how it's separating declarations for different OSs, sometimes using the latter, more compact declarations, other times highly redundant for no apparent reason. If we can hash out how it should be done, I'll submit a pull to fix it up.

Reply via email to