I propose that "?." and "?[]" operators be added to BrSc to make developers' life easier. They are just like the "unquestionable" operators, except check first if invalid and if so, return said invalid instead of raising error. E.g.
foo = bar?.baz ' bar.baz if bar is valid, otherwise invalid
foo = bar?[0] ' bar[0] if bar is valid, else invalid
This is not something i invented, it is present in VB.net, for explanation and example see
https://msdn.microsoft.com/en-us/librar ... cs-lang=vbThey call them "null-conditional operators" there, suppose could be "invalid-conditional dot" here (but i kind of like "questionable dot").
Another way of thinking of it, when having a chain of these like "a?.b?.c?.d?.e?.f" is "keep indexing by field till the end, unless you fail at some step; if you fail, return the last result in the chain". This would simplify life when working with roXML for example - instead of doing a ladder of "if"-s with separate handling of failures, to avoid exception - can type the whole expression and if the result is invalid, handle it all together.
And of course, the regular ("unquestionable") versions of the operators keep working as before by raising error on failure. Mixing is not a problem, subject to what we really wanted, e.g. in "a?.b.c?.d?.e.f" the ".c" will crash hard if lookup()/GetNamedElementsCi() are not applicable.
Anybody else in support of such operator?
If so, please reply with specific examples you know when this could be handy.
Scenographic example from me:
m.top.myCatalog[sect_id][prod_id].price
Maybe i should formulate this as a puzzle ... there is one specific "dot" above, that is extremely perilous and could fail at any time and unpredictably so, crashing the program. Which one is it, take a guess? 8-)
It would make sense being able to protect against that with "questionable operators"
PS. is "Doubting Dot(as)" a better name? "iffy index"?
🙂