D suffers from the same flaws with version(OSX).
My proposal:
systems.nim:
type Predef_OS=object
macosx:bool
linux:bool
# etc
type Predef_Nim=object
useNimRtl:bool
# etc; NOTE: other types can be used too (eg int, string)
type Predef=object
os:Predef_OS
nim:Predef_Nim
# etc
# this can be automated with a macro
const predef=Predef(
os:Predef_OS(
macosx:defined(macosx),
linux:defined(linux),
),
nim:Predef_Nim(
useNimRtl:defined(useNimRtl),
),
# etc
)
)
replace gradually all instances:
when defined(macosx)
# replace by:
when predef.os.macosx
# can also export `predef_os` if needed
when predef.os.osx #this'll result in a clean compile error instead of silently ignoring it
NOTES:
one possibility would be to define (in same file): proc isPosix(plaform:OsPlatform):auto=... and then replace:
when version(posix)
#by
when version(predef.os.posix) # what i am proposing above
when targetOS.isPosix # with system/platforms.nim + isPosix
Lol, please don't. I'm tired of nano improvements that make me touch thousands of lines of code. We need to ship what we have and call it a day. I don't remember mistyping these names all too often. And for other defines you can do:
when defined(foo):
const useFoo = true
elif defined(nofoo):
const useFoo = false
else:
{.error: "make up your mind, either compile with -d:foo or -d:nofoo".}
Enum are mutually exclusive but you can create predefined sets from the enums.
Regarding compile-time defines, my main issue is that a lot are hidden.
There is this wiki documentation: https://github.com/nim-lang/Nim/wiki/Consts-defined-by-the-compiler
Also not sure yet which flag for 32-bits or 64-bits architecture so I check sizeof(int).
Enum are mutually exclusive but you can create predefined sets from the enums.
using this? https://nim-lang.org/docs/manual.html#types-set-type is there any code using it for defined(...) ?
Regarding compile-time defines, my main issue is that a lot are hidden.
yes, that's another issue I have with current approach of defined(foo), there's no place to list them all; instead of a wiki it should be in code! that way stays in sync with code changes, etc.
defined(foo) should still be allowed of course when it's not practical to use predefined ones