-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Replace && and || with and and or #5238
Comments
+1 |
+1
|
I like this suggestion too. |
I'm a bit surprised by the groundswell of support this is getting. I've always felt that the spelled out operators were much more intuitive for control flow, but I didn't realize the feeling was widespread. |
I was not a fan when you made this proposition, but I must say after some more thinking it also makes much sense to me. These are really control flow operators, in contrast with all others, which use symbols rather than text. This may reduce the confusion with I've noticed that the languages which provide |
I personally like |
|
+1 Can also be added XOR as short circuit ? |
XOR is never short-circuitable. The other ones can be trivially written with |
+1 |
I would prefer for k <= n and k *= 2 |
Sometimes you want to assign the boolean result to something:
Which seems to conflict with that. |
Well, that's precisely why Ruby and Perl have both sets of operators with different precedence. Not advocating for that, but just saying. I'm not sure how common that usage actually is, whereas grepping through our code reveals a lot of |
Firstly, I'm also for
I think that this makes good sense (not sure about |
Btw, I think that a lot of people would expect that a language that uses |
I would be a little sad about |
I really don't think |
I agree with Stefan. The only thing |
I was just talking about initial expectations of new users. But I think |
I'd like to be contrary. Quite a few languages use && and ||, including all the ones I have used with any regularity, and those are always short-circuit. With and/or I'd have no intuitive expectation whether they short-circuit or not. I also like how && and || are clearly visually separated from variable names and numbers. The table at http://en.wikipedia.org/wiki/Short-circuit_evaluation may have some relevance for this discussion. |
As someone coming from the Python world I'm surprised to find myself in agreement with @GunnarFarneback. Lately I've found that the english conditionals ( |
I'm also for |
+1 |
+1 |
@johnmyleswhite this issue be closed? I think the ship has sailed on this one. |
:( |
short circuit that frowny face |
I understand that given aspiration to freeze code in a few weeks it may be to late to re-open this can of worms now (and I appreciate the idea of adding depreciations to leave door open for the future), but one thought: When this first came up for discussion (2013), I think the Julia community was primarily developers -- people with strong CS backgrounds who were more than used to using |
What's been proposed is reserving the |
I'd be fine with parsing these as permanent syntax errors, as we do with I also find it unfortunate that we're digging up old issues for which a decision has already been reached, especially so close to 1.0. |
To be clear: this gets done if someone does it. |
Thanks for the clarification! :D |
It seems very silly to me to bother parsing them and prohibiting other use, and nevertheless make it a syntax error. I think most people would rather not have situation where |
We've already decided not to parse them as aliases, that's why the PR was closed. So +1 for not parsing them at all. At the risk of rehashing this discussion which has been had ad nauseum, I'll note that regarding C and Ruby, using |
IMHO: seems like the original debates were rather divided, and adding this protection simply leaves space for the community to revisit it in the future it they'd like. |
I don't have any idea why this was reopened. |
A Julia dialect with syntactic features like this one could be done using JuliaParser.jl easily, once the internal and meta-programming APIs stabilize, can't wait for it! 😄 |
For those coming to this issue without having followed what has happened: Although the idea of using *) It seems as if the proposed change is less popular with more influential/"core" developers, so just looking at the number of 👍s may be misleading, though. I hope I didn't over-simplify and got things decently right. Apologies if I didn't. |
I don't see why it would ever happen if we've decided multiple times now not to do it. I hope we can avoid digging this issue up again for every major release. |
If Julia sticks around long enough to compete with Python, I can guarantee this will come up more and more. Many Python users don't want to return to C syntax. It's one of the many reasons Python is so popular: easy to learn, addicting to use, you won't want to go back the old way of doing things. New language designers often claim they want user-friendly syntax, yet they tend to get lost in fancy features only a tiny subset of users will ever want or use, while overlooking simple tweaks that could drive adoption. Case in point: bizarre Unicode operators are supported, but not natural language |
R also uses The only reason that seems to have been raised here is that Python uses |
I recognize this probably a dead issue, but in reply to @TomKellyGenetics, I would suggest that IMHO many of us would argue R qualifies as "older" and it not particularly user friendly... And while I agree that with beginners, |
I was referring to C-like languages, i.e. languages that heavily borrow syntax from C, usually with the self-fulfilling argument of 'it is the syntax every other language uses'. R syntax is rather C-like, though it diverges here and there. Julia is more Fortran-like than C-like, though there is some overlap.
IME students new to programming struggle with syntax on top of everything else, it's death by a thousand cuts. Programming is alien, and choosing abstract symbols over natural language makes it even more foreign and easy to forget. I often hear beginners in C-like languages ask things like, "How do you write 'or' again?"
Julia is not C or Fortran either. The vast majority of popular languages are C-like, so standing out usually means doing something different from C. I actually like Fortran, C and their descendants, use them all the time, but in some places they fall short and I think we can do better. Using more natural language is one way. It's worth noting that Fortran 77 and up use |
This issue has been resolved; |
There is a tendency to over-rate the importance of superficial syntax issues, since they are highly visible, easy to discuss, and their implications are usually clear. In another sphere, a language is considered unusable unless code blocks are surrounded by curly braces, in which case both julia and python are beyond the pale. I think it's debatable whether
To me, the old way of doing things is manual memory management and weak support for polymorphism, not the spelling of |
Julia has a few natural language expressions, such as FWIW, I voted to adopt both sets of operators, to ease adoption and give users style choices. In C++ projects where people use both it has never bothered me. I see no harm in it, only benefits. Overall I love the direction Julia's syntax has gone. A great balance between natural language and symbols, proving a numeric language can excel at general purpose programming. Can't wait to see how it grows and develops. Which is my way of saying adding the natural language operators is technically backwards compatible. 😁 |
I will give a shot at reserving |
#24965 ? |
Ah, missed that, thanks! I guess not reserving keywords doesn't prevent supporting these keywords in the future. |
Sorry, read all discussion, but still didn't got it, how can I use |
You can't |
As discussed at length in #5187, many of us would prefer that
&&
be written asand
and||
be written asor
.The text was updated successfully, but these errors were encountered: