by seemslegit · 6y ago · 0 comments
var (f, l) = person;
is so much worse than
var (f, l) = (person.FirstName, person.LastName);
I don't want to have to refer to documentation or class implementation to understand what a destructuring expression does.
var (first, last) = person;
didn't seem too bad to me.(the "Person" type would have to implement a "Deconstruct" method with two string out parameters, or alternatively someone could write an equivalent extension method)
var (f, l) = SomeMethodReturningAPerson();
than: var person = SomeMethodReturningAPerson();
var (f, l) = (person.FirstName, person.LastName);
or: foreach(var (f, l) in enumerationOfPersons) { ... }
compared to: foreach(var person in enumerationOfPersons)
{
var (f, l) = (person.FirstName, person.LastName);
...
}
When you know what you want to compute, but have to throw in extra temporary variables it becomes tedious and error prone. Cut straight to the thing you want (the names themselves in this case), eliminate middlemen.foreach(var (f, l) in enumerationOfPersons) { ... }
tells him absolutely nothing about what's going or even that there are names involved
foreach(var (firstName, lastName) in enumerationOfPersons) { ... }
is better but doesn't give him an object to inspect to see where they come from and what else is available.
var (f, l) = person;
is gross and hard to understand. var (x, y) = point;
is simple and readable.