-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add "not", "and", "or" keywords for logical operations #1749
Comments
@Boiethios I am not sure with you actually. There are some reasons why there aren't
|
@KalitaAlexey Only the third reason makes sense for me.
|
@Boiethios |
I also find |
@tshepang I miss too, but the main reason I don't want it: Having a choice between either and and or or && and || separates code into two pieces. |
|
@ubsan Yes you are right, we must include some header in C to have the macros for It was at first the reason in C++, but that is not the question here. The fact is some languages have those keywords and that some people prefer writing logical operator in a way closer to natural languages. |
They are used for readability too. |
I honestly think that the readability point is dubious. Sigils are easier to scan with your eyes, and especially in logical expression, that become very important, due to the effect on correctness. |
I think that's just a question of editor highlighting. Even if I sympathize with this feature request, I don't think we should have two identical ways to do the same basic operation. |
Come on, every editor put another color for keywords. |
@oli-obk @Boiethios Highlighting certainly solve part of the problem, but there is still a problem. Even with highlighting it is hard to distinguish between |
Okay I'm probably going to look grumpy with this message, but I think this idea of adding "or" and "and", and anything else from another language "just because it looks better" is not the right path to follow. If we are going to start doing this, what is preventing us from adding "elif" and "elseif" as well ? Not only it would be prettier for us to see, but it would allow people from python to not be lost as well. While we're at it, we can also add an optional "then" after the condition of the if, so that people from lua aren't as lost anymore. We could also add another when declaring variables, where we could say the type between the "let" and the variable name. Easy to detect, if the word right after a let or a let mut is a type, then infer this type automatically. This would get rid of "but I don't like the I think people from javascript will be lost too, and tbh "var" is easier to get, any beginner can see that we are declaring a new variable; as such I propose that we use "var" as another alias for "let". ... You get the idea. If we end up adding keywords that are aliases for things that already exist, we're going to have a very confusing language for new starters (and ourselves). Do you really want Rust to become another PHP, where 3 different ways are available for doing one very simple operation ? Get rid of that frown, I get your point: it's only "and","not" and "or". I personally prefer "&&" and "||" because they are widely used everywhere (except in Python, eh), not really because they are prettier/uglier/tastier than "and" / "or". But I would have been fine with "and" and "or" if the Rust language had been built like that. As long as there is one enforcing syntax, I would have been fine either way. |
I think the biggest problem here is that |
|
I'm against this. There's no clear advantage that it's worth the disruption. |
In my opinion it looks like BASIC.
replace:
It isn't a good idea, because it will only increase the complexity of the grammar. |
@Aatch I disagree with " |
While I personally do like the use of |
I'm going to close this issue. If I were designing a language from the beginning, I would probably prefer |
I think
Maybe it'd be better to enforce put a space between |
@eonil I tried to speak about this issue in reddit: https://www.reddit.com/r/rust/comments/8u8o5o/the_not_operator_in_rust/ TL; DR: I use the method instead of the operator and that's fine for me:
|
Like in some other languages (
Cpython, C++, etc.). I think those lines:are more readable than:
At least, if some people does not agree with me and prefer the second version, let's have the choice about what we want to use.
Please, the debate is not about why those keywords were introduced in C++. It it about the possibility (or not) to introduce them in Rust and talking about advantages and inconvenient.
The text was updated successfully, but these errors were encountered: