-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: "with" expressions for mutable objects #5676
Comments
How will you reconcile the difference in semantics between |
@orthoxerox |
@alrz wouldn't this still be too confusing? |
@orthoxerox Programmers should be familiar with this kind of "confusing"! For example const char* pstring = "";
char* const pstring = "";
const char* const pstring = ""; These are all different. |
So because a completely separate language has a confusing design for a completely separate feature means it's ok for C# to add confusing features? |
Factory initializers are a good idea. Using the same keyword that is specifically intended for use in immutable context for a mutability oriented feature is not |
Duplicate of #133? |
@ashmind the use case is partially the same but you didn't mentioned a practical syntax, it's the same as |
@aluanhaddad you're saying that this should use another keyword? my proposed syntax is based on the fact that these two basically do the same job with a different implementation. And since I'm against of totally immutable records (well, not algebraic types, just records; see #206 comment) this would make sense that you actually decide how you want to do this when you are doing it — like C++ classes; you decide where you want to put your variable (stack or heap) right when you are declaring it, not based on type. |
As an alternative syntax this could be done with no keyword at all e.g. scoping braces with a leading expression |
This has been concluded in #5365 but I thought it deserves a separate ticket. Also it can be considered as an extension to #5172 for using
with
expressions on other types.It basically provides a
With...End With
-like syntax for C# but as an expression.->
However, you can ignore the returned value if you don't need it e.g. after
with car { ... };
you can continue to use the existing variable.The text was updated successfully, but these errors were encountered: