-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
C# Design Notes for Jul12, 2016 #13022
Comments
@MadsTorgersen Will existing |
@MadsTorgersen Every type that implement ITuple can be deconstructed ? Which level of all specified in #11031 (Tuple syntax for other types) will be available ? Is it possible to add names for items (by fields (ItemName1, ItemName2, etc) or by function GetItemName(Index)) to ValueTuple ? This can be very helpful for reading data using reflection (for example databinding). |
What is the recommended naming convention for tuple item names, specially in case of a partially named one? If Are named tuples allowed in an is expression? Issues arise when recursive patterns are introduced in the language (#11744). |
No.
That is what the
I don't understand the question. |
We don't have recommendations at this time.
You mean on the left-hand-side? #11744 is about tuple patterns. |
Just for reference, I found #11205 useful in answering the questions about Deconstruct methods I wanted to ask. |
As for tuples with names I mean that code:
will create instance of ValueTuple with: Item1 = "John", Item2 = 5, ItemName1 = "name", ItemName2 = "age". For now ValueTuple type do not have fields ItemName1 and ItemNAme2. So I ask if you can consider and eventually add and use these fields ? |
@vbcodec We explicitly decided not to have names recorded at runtime. There is an identity conversion between tuple types for which only the names differ, and that would interfere with the identity conversion. |
Just my opinion about The reason I think it's better to think about features is because then the intent is well documented, it opens the door for future improvements, it's more reusable and overall in most cases it's more robust. However, if there's going to be more methods/properties on it like
Again, my opinion, I don't think that that having a long name should be a problem, I mean
My suggestion is don't use tuples in your public API and then you will save yourself a lot of headaches, if it's private or at least internal the convention isn't important but to you and your team, you can use whatever you feel is better and works for you. I feel like tuples should have been designed with limited access and it was much better if they disallowed exposing them to the outside world, aka, other assemblies but I guess there's a good reason for it, although so far I haven't seen a good use-case for this. |
But (#11205):
Does it mean the dynamic checking for deconstructability scenario would work differently than how the compiler checks it? Wouldn't it make more sense to have something like |
@miloush We do not have plans to make any changes to |
@gafter I see. And it's true that it is a language feature, not CLR feature, so that actually makes sense. So |
@miloush For the current design there's no need for CLR support but broadly speaking, it can easily be a feature that C# needs CLR support, it really depends on cons and pros of things and how you want to design it, therefor, it is a language feature by choice. |
That would be a suitable name if its method were named |
@gafter yes that was my concern, why is it realized through indexer rather than a |
No, currently the following code produces three errors on master, namely, class C {
bool M(object o) => o is (int, int); // tuple type
} Is this reserved to be parsed as a tuple pattern? |
Current Deconstruct method can degrade performance, as it read all data regardless what is needed. Indexer (like in ITuple) could be faster, although multiple calls also may not be fast. Maybe better is to modify Deconstruct method to provide additional integer parameter as bitfield to specify which members are necessary.. |
@miloush There is no signature for a @alrz Yes, the "is type" expression is not syntactically allowed to have a tuple type on the right-hand-side, as that is reserved for a tuple pattern. @vbcodec Deconstruction is not specified to be linked to any "members". If you want some particular data members rather than the result of |
@gafter Well, there is obviously one equivalent to the indexer, EDIT: not if implemented explicitly indeed |
@miloush Although your method is named |
@gafter I am aware of that, I am not claiming it should match the actual |
|
@DavidArno Except that only some of the users of existing code with a type |
To a certain extent, my comment was tongue-in-cheek. But there is a serious side to it. C# 3 came out nine years ago. Quite frankly, if someone still has a class called |
@DavidArno The point is that someone deliberately defines class named |
@stepanbenes I think that should be enforced via a code style analyzer, not an actual hack in the codebase. |
@alzr I agree. However, changing these rules for the new |
@alrz I wouldn't trust people who think type inference is a dangerous newfangled frivolity to know how to use a style analyzer. |
@orthoxerox Just make the style analyzer a dependency of the project and they don't need to know how to use it. 😝 |
The LDM notes for July 12 2016 are now available in the csharplang repo: https://github.com/dotnet/csharplang/blob/master/meetings/2016/LDM-2016-07-12.md I'll close the present issue. Thanks |
C# Language Design Notes for Jul 12, 2016
Agenda
Several design details pertaining to tuples and deconstruction resolved.
All or nothing with element names?
There's certainly a case for partial names on literals - sometimes you want to specify the names of some of the elements for clarity. These names have to fit names in the tuple type that the literal is being converted to:
Do we also want to allow partial names in types?
Yes we do. We don't have strong arguments against it, and generality calls for it. It's likely that there are scenarios, and not allowing will feel arbitrary. "The
bool
deserves a clarifying name, but theTypeSymbol
is clear".As a reminder, we distinguish between leaving out the name and explicitly specifying
Item1
,Item2
, etc. You get a warning if you useItem1
... in literals if they are not explicitly there in the target type. (Warning)`For the editor experience we imagine offering completion of a named element in the corresponding position of a tuple literal.
ITuple
ITuple
is really an interface for dynamically checking for deconstructability. Whether we should addITuple
now depends on whether we think we want to allow recursive patterns to do that, once we add them.We do think we want that.
We cannot use an existing collection interface (such as
IReadOnlyCollection
) because we want to be able to distinguish between deconstructable objects and collections (which might one day get their own pattern). It is fine for a class to implement both.ValueTuple<...>
should of course implementITuple
, and the translation of long tuples should work.The Framework team should chime in on the specific shape and names on the interface. Is
ITuple
the right name, or is it too narrow? IsIDeconstructable
more to the point or is it too long? Should it beSize
orLength
orCount
?var when var type exists
People use this trick to block the use of
var
, and we should let them, even though we disagree with the practice. So even though a type isn't valid in that position, we will let the presence of avar
type turn this into an error.var method
What if there's a method called
var
?Here there is no prior art, so we will always interpret the
var
to mean a deconstructing declaration. If you wanted the method call, parenthesize the call or use @.The text was updated successfully, but these errors were encountered: