Should a language support multiple returns?

There's endless style rules. Almost all have some basis in fact, almost all have very smart advocates, and you can't follow all at the same time because they conflict, and almost all will occasionally misdirect you. They're guidelines, not absolutes. Don't follow a guideline so far it defeats the point.

Multiple returns are really (in every language I can think of) actually one return - one tuple, one record or whatever. So why do we pack multiple values into one tuple/record/whatever? Not to meet arbitrary parameter/variable/return count targets, but because they're related, and make more sense kept together as a unit.

Having logically related details packed in one record/whatever helps readability, means you're less likely to get details from another record mixed in or pass the details in the wrong order etc. But if you're just packing unrelated details together to meet an absolute parameter count target, the "cure" is worse than the disease.

For multiple returns, to a point, packing multiple items together arbitrarily is just the idiom you use to return multiple values. In a sense (and sometimes literally) multiple arguments are also a single tuple of arguments. If you need to return multiple values, what's the alternative? Code duplication, writing essentially the same algorithm twice so one copy can give you one part of the result, the other copy gives you the other? A which-result-do-you-want switch as an argument, so your function does one of two things depending on the argument? Extra results in global variables, so you really still have both results but by the back door, and extra effects and referential opaqueness as a dubious bonus?

Don't overdo it, watch out for cases where details are logically related and should be packed together, but multiple returns are OK.

/r/ProgrammingLanguages Thread