Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please don't use ? as a unary operator? #17

Closed
carlobaldassi opened this issue May 25, 2017 · 7 comments · Fixed by #26
Closed

Please don't use ? as a unary operator? #17

carlobaldassi opened this issue May 25, 2017 · 7 comments · Fixed by #26

Comments

@carlobaldassi
Copy link

carlobaldassi commented May 25, 2017

See JuliaLang/julia#6286 (comment) and following comment and related discussions.
It's an old discussion, but it doesn't seem things have changed since (? could be possibly used a part of an identifier name in the future, not by its own).

Basically, the fact that using ? as unary works is an accident, and it makes things really difficult to parse.

@ararslan
Copy link
Member

It's a temporary hack until we can steal T? in Base to mean Union{T, Null}.

@StefanKarpinski
Copy link
Member

I don't see what the big problem with using ?T as a unary operator is. Sure, it's a nasty hack now that works by accident and awkwardly, but we could make it a true unary operator in the future.

@ExpandingMan
Copy link

ExpandingMan commented Jun 28, 2017

I personally find this to be a major annoyance. It totally screws up the parsing of julia-vim which makes it very unpleasant for me to work with it. For the time-being, can we use (almost literally) any other unicode character that is not already a binary operation of some kind?

@nalimilan
Copy link
Member

The long-term (1.0 or 1.x) plan is to use T? instead of ?T, which is consistent with other major languages like C# and Swift. See JuliaLang/julia#22523.

@carlobaldassi
Copy link
Author

I don't see what the big problem with using ?T as a unary operator is

One problem is that if you try to enter it in the REPL it goes in help mode.

As for parsing: right now, omitting a space in front of ? in ternary expressions is deprecated, but not afterwards. Which means that parsing ? as a unary operator correctly is still awfully context-dependent (I'm not just thinking about parsing in julia-vim, which I have kind of fixed, it's hard even for a human).

I believe that using ? by itself as an identifier should just be disallowed (mostly because of the REPL issue). Otherwise, at least spaces should be required on both sides to use it as a ternary operator, such that one can understand at a glance what's going on.

@nalimilan
Copy link
Member

One problem is that if you try to enter it in the REPL it goes in help mode.

That does not apply to T?, which has been retained as the long-term solution. Several other languages use that convention for a long time, and Swift recently adopted it, so it does not seem to cause big problems in practice.

@carlobaldassi
Copy link
Author

Yes, I was not speaking about T?, which doesn't cause any problems now that it's deprecated as a ternary expression. My points were specifically about expressions that start with ?, including using ? as an identifier/operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants