Tuples citizenship

kennytm kennytm at gmail.com
Thu Mar 1 15:38:04 PST 2012


"Jonathan M Davis" <jmdavisProg at gmx.com> wrote:

> When you're looking to mutate existing variables in the caller, using out 
> parameters results in cleaner code. Tuples are inherently messier, because you 
> have to deal with multiple return values. They also often do poorly when you 
> need to use the functional programming, because often you want all of the 
> return values for later use but only want to pass _one_ of them to the 
> function that you're passing the result to.
> 

You use 'ref' to mutate existing variable, not 'out'. Multiple return value
doesn't replace the use case of ref. 

Not sure how messy it is to extract one value out of the tuple. It is much
more messier to ignore an 'out' parameter than a field in a tuple in the
call site. 

> At other times, tuples are nicer - like when you actually _want_ the return 
> value packed together (though often, if that's what you really want, a struct 
> might be better). And if you're not looking to assign the parts of a tuple to 
> existing variables, then they're not quite as bad as when you are, since you 
> don't necessarily have to then assign the pieces to other variables.
> 
> Both have value, though if you need a lot of either, you should probably 
> consider whether a struct or class would suit what you're doing better.
> 
> - Jonathan M Davis


More information about the Digitalmars-d mailing list