Skip to content
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

Tuple types in using directives #15072

Closed
gafter opened this issue Nov 8, 2016 · 22 comments
Closed

Tuple types in using directives #15072

gafter opened this issue Nov 8, 2016 · 22 comments

Comments

@gafter
Copy link
Member

gafter commented Nov 8, 2016

It has been requested that we support

using Subject = (bool Gender, double Age);
@HaloFour
Copy link

HaloFour commented Nov 8, 2016

🍝 Generic version when combined with #3993?

using Subject<T> = (T Gender, double Age);

@iam3yal
Copy link

iam3yal commented Nov 8, 2016

That's pretty cool!

@DavidArno
Copy link

DavidArno commented Nov 8, 2016

At first glance, this seems an excellent idea. But then it takes on the texture of "aerosol cream": it looks like rich, thick, real cream but turns out to be 90% air. Yes, it would be useful occasionally, but the scope would then just be within that file. Some means of giving it a wider scope would really make this useful, eg:

Subject.cs

public global Subject<T> = (T Gender, double Age);

OtherFile.cs

bool GetGender(Subject<bool> subject) => subject.Gender; 

var gender = GetGender((false, 10));

Update
Having thought though this topic, I now feel that @alrz's point re records is pertinent. There should be no need for tuple aliases when we have records. So I no longer think this a useful feature at all.

@dsaf
Copy link

dsaf commented Nov 8, 2016

@DavidArno this was previously rejected for some reason #7451.

@DavidArno
Copy link

@dsaf,
That's a shame, but thanks for the link.

@MgSam
Copy link

MgSam commented Nov 8, 2016

I'm happy with the proposal as @gafter specified. I think generics and global scope are both orthogonal to this feature and should be considered separately.

@DavidArno
Copy link

Generics and global scope are enhancements to the basic proposal. So you appear to be misusing the term "orthogonal" 😛

@MgSam
Copy link

MgSam commented Nov 8, 2016

@DavidArno They are completely separable proposals that do not impact the merits of this feature as proposed. I'd call that orthogonal. Scope creep is the death of feature requests.

@qrli
Copy link

qrli commented Nov 9, 2016

I don't see this necessary. It is at best low priority.

If you want a type, define a type.

@alrz
Copy link
Member

alrz commented Nov 9, 2016

Once we have records, it'll be a piece of cake.

struct Subject(bool Gender, double Age);

I'd personally prefer to have generic and global type aliases over this.

@orthoxerox
Copy link
Contributor

@DavidArno records do not cover all the use cases you might need aliases for. See my example in #7453, there's no way a record can replace a long-winded generic interface type declaration.

@DavidArno
Copy link

DavidArno commented Nov 9, 2016

@orthoxerox,

Apologies, my comment wasn't clear. I was referring to this specific feature request: tuple aliases, not type aliases in general. I've updated my comment to fix that.

@alrz
Copy link
Member

alrz commented Nov 9, 2016

@DavidArno I'm saying that when you want a named tuple you'd better to define a struct record. But generic and global type aliases are useful for other scenarios, regardless of this proposal.

@AdamSpeight2008
Copy link
Contributor

Will the diposable form of using also be supported.

using ( ( MyDisposable0, MyDisposable1 ) )
[
  ...
}

@alrz
Copy link
Member

alrz commented Nov 12, 2016

@AdamSpeight2008 This is already supported:

using (IDisposable d1 = e1, d2 = e2) {}

Also see #9882 and #11420.

@AdamSpeight2008
Copy link
Contributor

@alrz That's not what I'm asking.
Let's we have this function.

Function Foo(Of T As IDisposable(Of T), U As IDisposable(Of U)) () As ( T, U )
End Function

And it is call within the header of a using block.

using( Foo() ) { ... }
 // Will both part of the Tuple<T,U> be disposed?

Do the Tuple<T,U> dispose correctly the disposable items within the tuple? eg .Item1 , .Item2

@HaloFour
Copy link

@AdamSpeight2008

#9882

@AdamSpeight2008
Copy link
Contributor

@HaloFour If the tuple is decomposed into separate variables, we risk the chance of disposing of a copy.

@HaloFour
Copy link

@AdamSpeight2008

That proposal goes over several potential implementations. Either way, this proposal is about using for aliases, not using for disposables. #9882 is about using for disposables and how that might relate to tuples, if at all.

@jcouv
Copy link
Member

jcouv commented Apr 8, 2017

@gafter Should this be moved to csharplang?

@gafter
Copy link
Member Author

gafter commented Apr 10, 2017

@jcouv yes, I'll move it.

@gafter
Copy link
Member Author

gafter commented Apr 10, 2017

Issue moved to dotnet/csharplang #423 via ZenHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests