Open timotheecour opened 4 years ago
Oh my, please ... no. I think it's a bad design, reminds me of sysctl
. It's faking simplicity.
i was half expecting that, and I kind of agree. Then this?
proc nimVerCT*(): tuple(int,int,int)
proc getExperimental*(): seq[Experimental] # type Experimental = enum ...
proc getBackend(): Backend
when nimVerCT() < (1,3,5) : ...
when Experimental.notnil in getExperimental(): ...
What's wrong with the existing solutions?
Hungarian-ish notation is redundant (querySetting, querySettingSeq, querySettingBool, ...)
like you've said yourself, stringly typed API's ("everything is a string / seq[string]") aren't user friendly in a static language that makes things like enum etc trivial to use
# we shouldn't need serialization + deserialization
doAssert querySetting("nimverct").parseTo((int,int,int)) == (1,3,5)
doAssert querySetting("assertions").parseTo(bool) # or reach for `system.compileOption` ... but why
and the compiler can't always help you if you misuse:
doAssert "forLoopmacros" in querySetting("experimental") # bug (wrong style => you'll silently get wrong answer)
doAssert "forLoopMacros".normalize in querySetting("experimental") # still buggy if you mistype
This is more user friendly, self documenting and impossible to misuse or you'll get CT error:
# either the "sysctl"-like way i gave in top post, or as individual procs, I'm agnostic:
doAssert nimVerCT() == (1,3,5)
doAssert Experimental.forLoopMacros in getExperimental()
doAssert assertions() # or maybe `nimQuery(assertions)` still in this case
compilesettings
so you don't have some arbitrary set of flags in system.compileOption
and some other arbitrary set of flags in compilesettings.{querySetting,querySettingSeq}
Well as long as it doesn't bloat system.nim further, I'm fine with more type-safe additions.
@araq ok with following?
proposal
compileOption
,querySettingSeq
andquerySetting
(or "soft" deprecate ie recommend the alternative here)why
RootObj
? because that's what used initerator fields*[T: tuple|object](x: T): RootObj
to allow returning a type that can depend on input argumentexample
note
compilesettings
stays a "low-level" module in the sense it's usable by low level modules (eg doesn't depend on iterators, dollars etc)implementation
no particular difficulty