-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoiding polymorphic values #164
Comments
Note that this (along with the "no boolean-ish values" thing from #96) should probably bet integrated into the https://github.com/opws/domainprofiles/wiki/Style-Guide at some point (which should itself migrate to whatever repo the schema goes to post-#147). |
See also #200, which also deals with values that can only mean one thing (ie. that if something is not present, it can only mean it's ambiguously-profiled, and not that it's nonexistent). |
Also, I think it's worth noting that the schema does have a kind of polymorphism, but only at the property level of objects via duck type (ie. where certain properties are mutually exclusive from others). |
I think some of this kind of boils down to "the schema will be verifiable with old, pre- |
Closing, pinging opws/opws-guidelines#3. |
I'm pretty sure the docs reflect this design already, for semi-conscious reasons (like, I think this is something I gravitated to and that older designs were looser about this), but I'll want to verify that there are no polymorphic values as I go into #146 and document the full, proper schema for real.
Why no polymorphic values? Well, because I want any code using these profiles to really only have one branch when it comes to evaluating values: it's either
undefined
, or it's present, and can be handled as one type - if it's an object or an array, you can jump straight from confirming its presence to testing its children, without having to sniff its type first to make sure you're not going to run into some error that includes the words "attempt to index".(Also, we don't use
null
or booleans likefalse
soif whatever
can be used to test if a value is present in Lua, andif (whatever)
can be used in most cases in other languages that are a bit looser with what they consider falsy. See #96.)If you know something will always be an array, you can test it with
if (whatever.field && whatever.field.indexOf(something))
. If it can be something else, you have to start throwing inArray.isArray
, or&& whatever.field != 'none'
, or stuff like that. While some languages will always have some amount of type-trickiness (JS, for instance, will haveif (whatever.field || whatever.field === 0)
wherever a numeric field can hold zero because, unlike Lua, JS considers zero to be falsy), I want to minimize it, especially when there's going to be enough trouble testing for the presence of deeply-nested properties all the way down.The text was updated successfully, but these errors were encountered: