Open mbyrne00 opened 8 years ago
I don't think having two ways of spelling the same thing is beneficial, it only creates more things to learn in the language without any benefit. It would be better to instead propose changing the name of coalesce
to something shorter, at which point I think nvl
is a really poor proposal since that name doesn't provide a direct insight into what the operator does, it is another thing one has to learn by heart, which adds to the complexity of the language.
I'm not saying coalesce
is a perfect word, the effect of the operator is not a perfect match for the dictionary definition of the word, but it is an actual word and it hints in the direction of what the operator does, and manages to do that while being pretty short. If we can come up with a word that does a better job by those criterions, changing it would probably be a great idea.
Just my 2¢.
I can see that sometimes an infix operator form may feel more natural as it gets less in the way of the intent of an expression. Scala uses OR ELSE
for chaining options, perhaps that would work here?
expr1 OR ELSE expr2 OR ELSE expr3
Alternatively, we could decide to spend an operator for this but the downside of that would be that it is much harder to read that without knowing it and it seems to small an issue to spend a special character on. If we go down that route, ?
might be a natural character to use since it is also used in the type system to indicate nullability.
@thobe I see your point about confusion in having two functions that do the same thing. Although the word coalesce
is in the dictionary, however, it's not a common word that you'd use every day. I know to use this function because it's common in other databases (ANSI standard), but other than that I wouldn't think to search for a function with this name.
Databases tend to require more special null
handling since null
doesn't equal null
like in some languages. The point of the ticket was to consider a shorthand since it could be used quite often.
It's commonplace for many languages to offer a shorthand for this, such as the elvis operator ?:
See here for examples: https://en.wikipedia.org/wiki/Null_coalescing_operator
That being said it was something raised in passing slack conversation and not a burning issue ;-)
How about |
?
So instead of COALESCE(v1, v2, v3 ...)
you could do v1|v2|v3...
. Since OR
is used for boolean arithmetic, the use of |
would not conflict with anything. And the syntax would read "v1 or v2 or v3, whichever comes first as non-null".
Updated the original comment to include the name of the CIR
Throwing in some more operator suggestions: v1 // v2 // v3
or v1 :+: v2 :+: v3
(monoidal combine operator)
CIR-2016-22
Since
null
handling can be common within a statement, writingcoalesce
every time can be a bit verbose. It would be nice to have some syntactic shorthand sugar for this.Oracle, for example, has the
nvl
function which is a more concise alternative tocoalesce
, which they also have (don't read this in any way as me being a fan of Oracle .... it's one of the only times their syntax is "concise").This all started from the casual slack conversation on the neo4j-users slack channel #help-cypher. Not a massive priority, but raised issue this at the request of Michael Hunger ...