Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# to use the left-hand side of the assignment

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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.
.



Relevant Pages

  • Re: Generic methods..
    ... T Product(T lhs, T rhs); ... T Negate(T arg); ... private static readonly IMathprovider; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: why is it so ?
    ... >>> (lhs, rhs) ... > Could you please tell me by which rule you have interleaved evaluation ... method of breaking up expressions using partial ordering by creating an ...
    (comp.lang.c)
  • Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# t
    ... I can't think of a situation where info flows from the RHS into LHS before the operation on the LHS can complete. ... However, using your analogy, it could be said that there are situations where the LHS participates in the equation independently from the RHS. ... The introduction of "var" was radically different, in that the barrier which kept each side from influencing the other was broken down. ... Can you think of any other statement or expression where info flows from the RHS into LHS before the operation on the LHS can complete? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Slight problem using user-defined types with STL sets
    ... > I've got a fairly basic question about STL sets and operator overloading ... bool operator<(const twotuple& lhs, const twotuple& rhs) ... rhs are equivalent with respect to the first coordinate but lhs is less than rhs ...
    (comp.lang.cpp)
  • Re: A good ride, ruined
    ... straight into it, on the LHS, knocking it over onto its RHS. ... always, the superficial damager didn't ...
    (uk.rec.motorcycles)