by ComputerGuru · 10y ago · 0 comments
Old example:
bool Hello(string name) {...}
var myName = "world";
Hello(myName);
The developer can change the name of variables in the prototype to be more (or less!) descriptive without a problem - they're decoupled.New example:
(string interjection, string name) GenerateGreeting() {...}
var greeting = Greeting();
Console.Write("{0} {1}", interjection, name);
Now should the author change "interjection" to "greeting", _ your code won't compile _ and in a way that you likely didn't expect. string interjection;
string name;
(interjection, name) = GenerateGreeting() {...}
I can't believe the C# team would introduce something so brittle into the language. If you're right, that a serious concern.[edit] unless you're talking about how your example magically introduces "interjection" into the scope. That's not how it works. You would have to say "greeting.interjection". Or use the destruction syntax and say "var (ichosethis, andthis) = generateGreeting();", in which case its the order of the fields, not the name of them, that is important.
But that's the same as named parameter, and you didn't complained, if the client used named parameters and you change them it will break their code. The full signature of the method is the public API, as you can see when navigating a compiled assembly.
(string first, string last) name = GetName();