Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Wed, 17 Dec 2008 23:07:45 -0800
"Jeff Johnson" <i.get@xxxxxxxxxxx> wrote:
"Anthony Jones" <AnthonyWJones@xxxxxxxxxxxxxxxx> wrote in message
news:e0lUIpJYJHA.5476@xxxxxxxxxxxxxxxxxxxxxxx
Sorry it doesn't get my vote.
The RHS is no longer independant of the LHS and that is just
mathematically wrong. The other way round (as in the case of var) its
fine.
I'm also unclear on what actual problem is being solved by it.
The problem is "unnecessary wordiness."
Why oh why must you write MyClass TWICE:
MyClass c = new MyClass();
when you could just do
MyClass c = new();
This would be an OK idea if "= new()" were a single operator. The problem
with this proposal, as I see it, is that "new" is a general-purpose
operator that can be used in other ways. What you are proposing requires
an ugly and intrusive change to the expression parser. Right now, the
parser sees this:
LHS = RHS;
It is then able to evaluate the RHS using normal expression parsing, then
evaluate the LHS using the lvalue parsing, and connect them together with
an assignment
Your change would require special-casing to say
IF this is an assignment statement
AND the left hand side declares a new variable of type X
AND the right side consists only of a "new operator"
THEN assume that the "new" operator should create a type X".
That's very intrusive, and I'd be surprised if there were any single spot
within the compiler to insert this.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- Follow-Ups:
- References:
- Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- From: Anthony Jones
- Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- From: Jeff Johnson
- Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- Prev by Date: Re: Screenshot of the form
- Next by Date: Re: Bogus control property values
- Previous by thread: Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- Next by thread: Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment
- Index(es):
Relevant Pages
|