Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Poll: until in addition to while #562

Closed
lachbaer opened this issue May 10, 2017 · 14 comments
Closed

Poll: until in addition to while #562

lachbaer opened this issue May 10, 2017 · 14 comments

Comments

@lachbaer
Copy link
Contributor

Because it always comes up from time to time 😃

The until keyword is available in many other programming languages and is made much use of. In C-derived languages however it does not exist, because it can be expressed by while (!(...)). Nevertheless, there seem to be quite some people who would like to have it additionally, not only in C#.

This poll is not about discussing until! It shall only be a rough survey on how community members currently think.

Sample:

do {
    PullNewItems(itemlist, source);
    Process(itemlist);
} while (!(list.IsFull || source.IsEmpty));

vs.

do {
    PullNewItems(itemlist, source);
    Process(itemlist);
} until (list.IsFull || source.IsEmpty);

Poll

  • ❤️ I would love to see it in the language soon (it eases conditions for me)
  • 🎉 If it were available I would certainly use it instead of while (!...)
  • 👍 It's okay, I might use it sometimes instead of while (!...)
  • 😃 I don't care, but I'll most probably stick with the existing while construct
  • 👎 It does not belong in the language! All users shall learn while(!...) as reading 'until' if they like
  • 😕 The other options don't reflect my opinion. Feel free to comment below.
@DavidArno
Copy link

Just did a search of my code: I have zero occurrences of do while in that code. So it's a 😕 from me as I'd probably not use do until either.

@lachbaer
Copy link
Contributor Author

@DavidArno do ... while is just in that example. It could be while (cond) ... also. Do you have while (!...) ... in your code?

@DavidArno
Copy link

DavidArno commented May 10, 2017

Good point. Yes, I found half a dozen or so uses of while. In all cases the expression was a positive one (no occurrences of while (!expression), so until wouldn't work for me. So I've changed my vote to 😄

@lachbaer
Copy link
Contributor Author

Sorry, I'm clearly the wrong audience for this feature 😃

That's what this survey is about 😄

@HaloFour
Copy link
Contributor

In 60 years nobody has felt the need to add it to C/C++. Not even D added it. I just don't think it's necessary.

I'd be much more for exploring allowing the ! operator to appear outside of the parenthesis, which could apply to both if and while:

do {
    PullNewItems(itemlist, source);
    Process(itemlist);
} while !(list.IsFull || source.IsEmpty);

@lachbaer
Copy link
Contributor Author

I'd be much more for exploring allowing the ! operator to appear outside of the parenthesis,

It would be interesting to have a poll for this, though I doubt that the team is susceptible to that neither. Should that poll be concurrent to this one or better delayed until many more have voted here?

@HaloFour
Copy link
Contributor

I have my doubts that the team are considering these polls much in general. The participating audience here is just too small. It's not like UserVoice where we're amassing thousands of votes.

I'll put up a separate proposal/discussion for the ! idea, though.

@lachbaer
Copy link
Contributor Author

I have my doubts that the team are considering these polls much in general.

The idea of the polls is to get a rough overview about how the community here is thinking in general without provoking a confusingly long discussion where the overview could be lost quickly.

@whoisj
Copy link

whoisj commented May 12, 2017

This is much like the if !(condition) discussion. Simply omitting the parenthesis would fix the issue.

while !condition or while condition or do { ... } while condition; or do { ... } while !condition;, and of course the parenthesis would remain perfectly legal so that if (condition) would legal, and in many project required I'd assume. 😏

@svick
Copy link
Contributor

svick commented May 12, 2017

@HaloFour

In 60 years nobody has felt the need to add it to C/C++.

I don't think that's a valid argument. In 60 years, nobody has felt the need to add LINQ or expression-bodied members or pattern matching to C/C++ either. Especially C is a very different language than C#, with very different goals.

@HaloFour
Copy link
Contributor

@svick

Sweeping language features are a little different from minor grammar tweaks (well, expression-bodied members definitely fall into that latter category). All it does is move the negation from the expression and into the keyword, adding another way of doing something you could already do. Is it more readable? Perhaps in some scenarios. It's exceptionally minor, but in my opinion so is the benefit. And it may open the door to applying elsewhere in the language. We've already had requests for unless to negate if.

Even looking at the discussion of removing the parenthesis to make negation a little "clearer" has only opened a can of worms of horrific code rife with ambiguities.

@Thaina
Copy link

Thaina commented May 12, 2017

I don't like the idea of adding new keyword. I prefer if! and while!

All keyword should be operator

@lachbaer
Copy link
Contributor Author

Meanwhile I'd prefer having until only as a conditional for the do statement.

Starting a 'sentence' with until looks somehow strange to me. And there is no other language I know that starts a statement with until.

But as a final conditional keyword in a do-loop I still think that it can be useful:
do { ... } until (condition)

@gulshan
Copy link

gulshan commented Apr 21, 2018

I think whether until will be useful can be decided objectively. Some source code scrapper can look for use of while and do...while and then check whether the condition for while is negative or not (starts with ! or not). If the negative conditions are of a higher percentage, adding until and do...until loops will be helpful for programmers. One can argue that why introduce a new keyword when we can just have while not? I think, until is more intuitive than while not.

@dotnet dotnet locked and limited conversation to collaborators Dec 3, 2024
@333fred 333fred converted this issue into discussion #8725 Dec 3, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants