Replies: 24 comments
-
I think this is valuable for ideological reasons. Tuples should be like argument lists as much as possible. |
Beta Was this translation helpful? Give feedback.
-
I wonder if the proposal (multiple My initial reaction would be to keep a single |
Beta Was this translation helpful? Give feedback.
-
Tuples should be used as self-explanatory and short-lived combination of values. I think a better solution is to use a record instead, if we want to provide documentation. Same would be applied to generic delegates, you will probably define a special delegate type if you're going to document parameters etc. |
Beta Was this translation helpful? Give feedback.
-
I don't think this breaks down. If |
Beta Was this translation helpful? Give feedback.
-
Yes, tuples can nest and nesting may allow for leaf tuples to have same names. |
Beta Was this translation helpful? Give feedback.
-
I agree with @alrz, tuples really aren't well suited for public APIs or scenarios where you'd need or want to document them, at least beyond what the element name metadata already provides. If you have an accessible method that returns a complicated tuple (particularly nested) and you feel that you need to use XML documentation, you probably should be explicitly declaring a concrete class. |
Beta Was this translation helpful? Give feedback.
-
The other thing about public APIs is, what happens when you want to add a field to the return type? That's only a non-breaking change if you own and mutate the type definition. I don't know if we should try too hard to support them except for the ideological parity with argument lists. And here maybe it's just not worth it? |
Beta Was this translation helpful? Give feedback.
-
I agree that something like this should be supported as it does provide parity with argument lists. As for the arguments that tuples shouldn't be used as a return type in a public API, I agree that the "original" tuples (all of the Instead of multiple /// <summary>
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>
/// <returnref name="s">[description for s]</returnref>
/// <returnref name="t">[description for t]</returnref>
/// </returns>
static (int s, int t) F(int x, int y)
{
return (x + y, x - y);
} |
Beta Was this translation helpful? Give feedback.
-
@scottdorman I would expect |
Beta Was this translation helpful? Give feedback.
-
@jnm2 I can use /// <returns>When this method returns, <returnref name="s">is a positive non-zero value</returnref>
/// and <returnref name="t">is a negative value</returnref>.</returns> |
Beta Was this translation helpful? Give feedback.
-
@scottdorman You're right, I didn't communicate that very well. Let me put it this way.
But your |
Beta Was this translation helpful? Give feedback.
-
What happens in the case of nested tuples? static (int s, (int s, int t) t) F(int x, int y) { ... } |
Beta Was this translation helpful? Give feedback.
-
@jnm2 Correct. So maybe @HaloFour I would think I'd be able to refer to it as |
Beta Was this translation helpful? Give feedback.
-
How about the case of generic type arguments? static Task<(int s, int t)> FAsync() { ... } Can |
Beta Was this translation helpful? Give feedback.
-
@ufcpp I think so. In that case, you're still returning a single |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@HaloFour Nice one! :) <returnref name="a`1">
<returnref name="a`2"> or <returnref name="a#1">
<returnref name="a#2"> |
Beta Was this translation helpful? Give feedback.
-
Given all these examples, I'm starting to dislike the whole idea. From a pragmatic standpoint, what do you expect to see in the IDE? You only see (c, d) = Foo(a, b); There's no point in |
Beta Was this translation helpful? Give feedback.
-
@jnm2 XML doc comments are for more than just IntelliSense, though. Yes, I don't think these would show up in IntelliSense. |
Beta Was this translation helpful? Give feedback.
-
Anything done on this? What should the syntax be? As people go for more functional style programming, in order to get concurrency correct, more and more tuples will be returned by functions, and named tuples really makes this simple. We need to be able to document it in a standard way. |
Beta Was this translation helpful? Give feedback.
-
This is a much-needed feature, especially when working with the return type and referring it by Item1, Item2, and so on. Need to know exactly what its function is or at least a hint about what exactly it is. Having to scroll and look into the method signature every single time, painful. Regards, |
Beta Was this translation helpful? Give feedback.
-
If we just had the ability to reference tuple names in For example: /// <returns>
/// A <see cref="ValueTuple{Color Color, Boolean IsDark}"/>,
/// where the <see cref="ValueTuple{Color Color, Boolean IsDark}.Color"/> is the background color,
/// and the <see cref="ValueTuple{Color Color, Boolean IsDark}.IsDark"/> describes whether the background color is considered dark.
/// <see cref="ValueTuple{Color Color, Boolean IsDark}.IsDark"/> is indented to facilitate choosing a suitable foreground text color that
/// maximizes readability and contrast on the background color.
/// </returns> or, potentially more ideally, remove the need to use /// <returns>
/// A <see cref="(Color Color, Boolean IsDark)"/>,
/// where the <see cref="(Color Color, Boolean IsDark).Color"/> is the background color,
/// and the <see cref="(Color Color, Boolean IsDark).IsDark"/> describes whether the background color is considered dark.
/// <see cref="(Color Color, Boolean IsDark).IsDark"/> is indented to facilitate choosing a suitable foreground text color that
/// maximizes readability and contrast on the background color.
/// </returns> |
Beta Was this translation helpful? Give feedback.
-
Ported from dotnet/roslyn#13216
multiple returns tags and name attributes in doc comments for a tuple return value
Summary
The most common use case of tuples is to return multiple values from a method. Tuples are designed as counterpart to method parameters. And
param
tags in XML doc comments has aname
attribute for each parameter. Thus,returns
tags should have aname
attribute for each tuple element too.Motivation
So far, I have to write doc comments as the following code. The method
F
has two resultss
andt
, but the doc comment cannot have their names.This is inconvenient because the following features can not work well.
Proposal
I'd like to write as the following. Let the
returns
tags have aname
attribute for tuple element name.Drawbacks
This feature requires implementation in not only a C# compiler but also related tools such as Sandcastle.
Beta Was this translation helpful? Give feedback.
All reactions