Project Elvis

Nathan S. no.public.email at example.com
Fri Nov 10 23:11:34 UTC 2017


On Monday, 6 November 2017 at 12:25:06 UTC, Biotronic wrote:
> I find I often use this in C# with a more complex expression on 
> the left-hand side, like a function call. A quick search shows 
> more than 2/3 of my uses are function calls or otherwise 
> significantly more complex than a variable. Also, it works 
> great in conjunction with the null conditional:
>
> foo.Select(a => bar(a, qux)).FirstOrDefault?.Name ?? "not 
> found";
>
>> It seems to be targeted primarily at code that does a lot with 
>> classes and is written in such a way that it's not clear 
>> whether a class reference should be null or not, whereas most 
>> D code doesn't do much with classes.
>
> In my C# code, it's used with strings and Nullable<T> more 
> often than with classes.
>
> Given my own experience with the ?? operator, I'd argue it's 
> probably not worth it without also including null conditional 
> (?.). A quick search in a few projects indicate roughly half 
> the uses of ?? also use ?..
>
> --
>   Biotronic

Without including ".?", this proposed "Elvis operator" will just 
be ECMAScript-style "||". I think it will still be useful because 
"||" is useful, but it would be more elegant to just allow "a || 
b" to have the common type of "a" and "b" (which wouldn't change 
the truthiness of the expression) instead of introducing a new 
operator that is exactly like "||" except it doesn't force the 
result to be bool.


More information about the Digitalmars-d mailing list