3 ms·
What's the point of GetCoordinates(out var x, out var y) over destructuring assignment like var x, var y = GetCoordinates(); the former looks comple
by ricardobeat 10y ago
What's the point of
GetCoordinates(out var x, out var y)
over destructuring assignment like
var x, var y = GetCoordinates();
the former looks completely backwards.
- masklinn 10y agoThe former works with pre-tuple out-parameter-based API e.g. Int32.TryParse.
- frogfuzion 10y agoMaybe the former method would make more sense to use if it were HasCoordinates and returned a Boolean? This way you would get a Boolean if the coordinates exist and would not have to perform validation on the out variables.
- reitanqild 10y agoWondered about this myself, is this something that is needed for backwards compatibility or something? IMO fishing parameters back from functions is one of the things I do not miss from old C. Anyone has anything to add to masklinn's explanation? Edit: found CyrusNajmabadi's comment here: https://news.ycombinator.com/user?id=CyrusNajmabadi https://news.ycombinator.com/user?id=CyrusNajmabadi
- 72deluxe 10y agoI much prefer your second example. In fact, surely tuples would help in this situation? eg. in C++: tuple<int,int> x = GetCoordinates(); or auto x = GetCoordinates() Much easier to see the output. I maintain enough old old C++ code and don't like seeing GetCoordinates(int x, int y) or x in COM-land any more.