Project Elvis
codephantom
me at noyb.com
Wed Nov 8 08:35:37 UTC 2017
On Wednesday, 8 November 2017 at 07:32:05 UTC, aberba wrote:
>
> I have gone through all the threads and none of the comment
> argues why we REALLY need Elvis in D. Seem to me like some kind
> of "language peer influence" or something.
>
Presumably, it's just a more 'elegant' (less verbose) way of
doing something that can already be done.
-- taken from:
https://kotlinlang.org/docs/reference/null-safety.html#elvis-operator
val l: Int = if (b != null) b.length else -1
Along with the complete if-expression, this can be expressed with
the Elvis operator, written ?::
val l = b?.length ?: -1
----------
But I can understand the first example really easily.
The second example, with the elvis operator, I have to spend
'more time' making sure I've interepreted those little symbols
correctly. I don't like this syntactic 'elegance' at all. The
human brain has too much trouble with it, unless it comes into
contact with it often.
So as someone once said, "one has to be very suspicious of the
elegant solution" - Butler Lampson 1992.
More information about the Digitalmars-d
mailing list