GithubHelp home page GithubHelp logo

Shorthand for coalesce about opencypher HOT 7 OPEN

opencypher avatar opencypher commented on May 5, 2024
Shorthand for coalesce

from opencypher.

Comments (7)

boggle avatar boggle commented on May 5, 2024 1

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.

from opencypher.

thobe avatar thobe commented on May 5, 2024

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ยข.

from opencypher.

mbyrne00 avatar mbyrne00 commented on May 5, 2024

@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

from opencypher.

mbyrne00 avatar mbyrne00 commented on May 5, 2024

That being said it was something raised in passing slack conversation and not a burning issue ;-)

from opencypher.

ADTC avatar ADTC commented on May 5, 2024

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".

from opencypher.

petraselmer avatar petraselmer commented on May 5, 2024

Updated the original comment to include the name of the CIR

from opencypher.

boggle avatar boggle commented on May 5, 2024

Throwing in some more operator suggestions: v1 // v2 // v3 or v1 :+: v2 :+: v3 (monoidal combine operator)

from opencypher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.