Replies: 25 comments
-
This is a breaking change since locals always take precedence over fields in binding. |
Beta Was this translation helpful? Give feedback.
-
@alrz I think it about how we translate syntax into block I mean, normally we always count only |
Beta Was this translation helpful? Give feedback.
-
This is a working example that will break with this change: bool cond; // field
void M() {
do {
string cond = "";
} while( cond );
} I'm not aware of any scoping rules that alter that precedence based on context. |
Beta Was this translation helpful? Give feedback.
-
Thank you for enlighten me |
Beta Was this translation helpful? Give feedback.
-
I've long wondered why the while condition couldn't share scope with the body, but here we are. I don't think new syntax is better than moving the declaration of of the loop though. Edit: scope not scoops. I have a really weird phone. |
Beta Was this translation helpful? Give feedback.
-
@jnm2 For the concern that @alrz present I think we cannot directly extend scope out easily. But new syntax I said might be little tweak Such as do
{
bool cond = false;
}for(!cond); or maybe just do
{
bool cond = false;
}(!cond); |
Beta Was this translation helpful? Give feedback.
-
I guess what I'm saying is, since the past is the past, rather than adding new syntax, what's so inconvenient about this: bool cond;
do
{
cond = false;
} while (!cond); It's about as few words as it would be with new syntax anyway, and it doesn't complicate by adding new syntax. If you really wanted to use the name { bool cond;
do
{
cond = false;
} while (!cond); }
{ bool cond;
do
{
cond = false;
} while (!cond); } |
Beta Was this translation helpful? Give feedback.
-
@jnm2 Well I just confuse for what you saying a little. I didn't understand that you disagree. But that's ok. I just think what we currently did is dirty code (include what you present me). It should be compact and encapsulated. That's purpose of proposal Same reason why we introduce |
Beta Was this translation helpful? Give feedback.
-
You make a good point. This isn't common enough in my code to justify adding language syntax, but others may have different experiences. |
Beta Was this translation helpful? Give feedback.
-
I'd argue that if we keep the existing syntax, but include the loop condition in the scope of the body, if you do this: private bool cond;
void Foo()
{
do
{
bool cond = false;
} while (!cond);
} It would not be the worst thing in the world if the compiler gave an error that there is a conflict between |
Beta Was this translation helpful? Give feedback.
-
Normally I just do thing like this //DoSomething n lines
while(!condition)
{
//Copied of DoSomething n lines
} or worse while(!DoSomethingPassed(param))
{
}
bool DoSomethingPassed(param)
{
//DoSomething n lines
return cond;
} or worst while(true)
{
//DoSomething n lines
if(cond)
break; // or return
} Which is too dirty. Using |
Beta Was this translation helpful? Give feedback.
-
Problem is it used to be valid code. So there could be in some codebase of some people in the world. And it would give error when they try to recompile it Which is called breaking change |
Beta Was this translation helpful? Give feedback.
-
Yes. Rather than complicate the syntax 99.99% of the time, I'd prefer we make the 0.01% people take a breaking change.
|
Beta Was this translation helpful? Give feedback.
-
@jnm2 I really want to agree with you but in the hat of proposer I need to take the safest route |
Beta Was this translation helpful? Give feedback.
-
@Thaina Can we at least float both options? I see only benefits to the breaking change and it feels so much cleaner than adding syntax. /cc @CyrusNajmabadi |
Beta Was this translation helpful? Give feedback.
-
That said, this seems like exceptionally marginal value. This would fall quite low on my list, and I'd far prefer we work on other stuff. Just my 2c here. |
Beta Was this translation helpful? Give feedback.
-
Just to clarify, @CyrusNajmabadi, you're saying that if this language feature was top priority for C# 8.0 for whatever reason, you'd still prefer adding new syntax to the language over this type of breaking change, taking the points I outlined above into consideration? I'm interested in the general principle here. |
Beta Was this translation helpful? Give feedback.
-
Yes. We are loath to make breaking changes. Generally, we only will if at a minimum all the following apply.
Right now none of those even apply (let alone all three). |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi, @jnm2, @Thaina There might be a place for |
Beta Was this translation helpful? Give feedback.
-
I'm having syntax fatigue. Personally I'd prefer to put up with moving the declaration rather than think about two syntaxes. |
Beta Was this translation helpful? Give feedback.
-
@jnm2 Haha.. well, it's not new I mean |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi would it counted as breaking change just tweak syntax like I was present? do
{
bool cond = false;
}(!cond); // why we need while here anyway? Legacy from C?
//or
do
{
bool cond = false;
}for(!cond); |
Beta Was this translation helpful? Give feedback.
-
That would not be a breaking change. But that doens't mean we'd take it. C# syntax has to feel adequately CSharpy. I'm not sure either of those apply. The first just looks like you forgot the It's not sufficient to just be non-breaking-syntax. It also has to feel appropriate. To me, those don't fit the bill. |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi Thanks for your clarify. I just make sure I can hope for some way like that would not be breaking change |
Beta Was this translation helpful? Give feedback.
-
How about this?
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Whenever we want to do
do{}while();
loop. Most of condition logic would actually use in this block, never gone outSo I think it would be more benefit if we could let
while
access variable indo
blockLike this
So variable in the scope will be encapsulated only where it used. Not be seen outside
Beta Was this translation helpful? Give feedback.
All reactions