Replies: 11 comments
-
This will collide with the proposed functors. |
Beta Was this translation helpful? Give feedback.
-
For reference, the functors proposal in the Roslyn repo (dotnet/roslyn#14731) has been closed in favor of it's equivalent one (#95) in this repo. |
Beta Was this translation helpful? Give feedback.
-
The ': this/base' syntax wouldn't collide. public int Skip() => static.this(1);
// vs.
public int Skip() => this.static(1); // or base.static(1) |
Beta Was this translation helpful? Give feedback.
-
That makes the syntax even messier and more confusing, in my opinion. |
Beta Was this translation helpful? Give feedback.
-
How is (Not that the |
Beta Was this translation helpful? Give feedback.
-
I admit that #95 would be much more useful! And it conflicts partly with the syntax of this proposal. But I still think that there is meaningful use in not repeatedly stating the functions own name again. Like in the use case I had with my dozens of classes that I had to change manually. |
Beta Was this translation helpful? Give feedback.
-
Wouldn't a refactor|rename operation have worked for that? |
Beta Was this translation helpful? Give feedback.
-
Yes, it probaby would have but with more clicks. And I want to quote myself:
I withdraw the part of this proposal reagarding in-method-body-calls to There are currently no real comments on the 'constructor-like' syntax I described here. In my eyes it has a consistend style and could help to write compacter code in case of overloading and overwriting. |
Beta Was this translation helpful? Give feedback.
-
Updated the initial proposal. |
Beta Was this translation helpful? Give feedback.
-
Constructors need this as the very first thing they have to do is delegate as appropriate. That's not the case for methods at all. Methods may call an overridden member anywhere in their execution block (including multiple times). Providing syntax to special case precisely one of these seems incomplete. |
Beta Was this translation helpful? Give feedback.
-
This is only about readability and shortening, exactly as expression syntax for methods is (for users): void CalculateSumAndRaiseEventWithResult(int[] values) : base(values)
=> RaiseChildsAdditionalCompletedEvent(); is simply easier and shorter to read and write than void CalculateSumAndRaiseEventWithResult(int[] values)
{
base.CalculateSumAndRaiseEventWithResult(values);
RaiseChildsAdditionalCompletedEvent();
} Just an idea, calling a value returning function results in an additional parameter int CalculateSumAndRaiseEventWithResult(int[] values) : int result = base(values)
{
RaiseChildsAdditionalCompletedEvent(result);
return result;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to propose calling the same method name by re-using
this
andbase
keywords.[Update:] The initial proposal has been withdrawn by the author. But the second part shall still stand.
Updated Proposal
For
void
returning methods a call to another overload in the same (this
) orbase
class can be made by using the same syntax as for constructors:...for
: this(...)
respectively.If I haven't overseen anything it would not conflict with any other use of
this
orbase
and be consistent with the constructor syntax.Benefits
Initial proposal (withdrawn)
Let's say you have a recursive funktionWhen you are going to rename the function, you don't have to rename the occurences within the function. (I know that IDEs can help here... )Another use would be to call an overloaded function:The same should be true for calling the base class, e.g. for the following common patternAlso for
void
returning methods the syntax could be extended like for constructors...for
: this(...)
respectively.If I haven't overseen anything it would not conflict with any other use of
this
orbase
and be consistent with the constructor syntax.Beta Was this translation helpful? Give feedback.
All reactions