2 ms·
I remember Groovy didn't allow ? on indexes like in the third C# example: int? count = customers?[0]?.Orders?.Count(); I remember asking for it but it never
by vorg 11y ago
I remember Groovy didn't allow ? on indexes like in the third C# example:
int? count = customers?[0]?.Orders?.Count();
I remember asking for it but it never came. I don't think Ruby's proposed .? syntax would work with indexes either unless they use [? ].
Neither Java nor Groovy has the int? declaration shown which enforces the optionality. The C# version looks more versatile.
Back when Groovy was more popular, its backers also discussed a cascading ? on their mailing list but it never happened. If C# had cascading ? then the example above would be
int? count = customers?[0].Orders.Count();
because the first ? would ripple to the subsequent member accesses and index lookups.
- richmarr 11y agoYep. I remember waving my arms and crying for ES6 to have '?.' back when the spec was open, but there was a lexical issue. It's frustrating to have such useful features blocked by such seemingly small problems as ambiguous patterns of characters.