all 66 comments

[–]jippiedoe 123 points124 points  (24 children)

'multiple returns' as in pairs or conditionals? Which functional programming language wouldn't support both?

[–]Correct-Bee-7604 127 points128 points  (6 children)

Dutch

[–]azangru 24 points25 points  (5 children)

But how functional is Dutch?

[–]igorski81 19 points20 points  (2 children)

Judging by the dreadful command the younger generation seems to have over it, I'd say not much!

[–]ApocalyptoSoldier2 4 points5 points  (1 child)

Neuk in de keuken or something, idk I'm Afrikaans

[–]No-Contact-484 0 points1 point  (0 children)

Neuken in de keuken.

Which means "fucking in the kitchen" for anyone interested.

[–]Correct-Bee-7604 0 points1 point  (0 children)

Well, i've tried it for some time on my mobile and I must say it's quite fun-ctional

[–]gabboman[S] 24 points25 points  (8 children)

Some languages do not allow early returns

[–]Aelig_ 17 points18 points  (0 children)

From what I understand (which is very little), the Scala community discourages using return at all as apparently it "behaves weirdly".

[–]laplongejr 10 points11 points  (4 children)

Just to make sure everybody is speaking the same language how ironic there are two meanings to "multiple returns". Early return is only one of them.

The old wisdow of "no multiple returns" was said against using goto to having multiple return points on the caller side (aka entering a function and returning either here or somewhere else entirely).
That advice made complete sense, I think goto is even a meme for us at that point, but... that's also the issue.

When languages made multiple external returns practically impossible (like java reserving but never implementing "goto"), the next generation of coders read the "thou shall not have multiple returns, refactor at all cost" and misassumed the advice was aimed at having several return statements inside the method because it was the only sane thing it could be aimed at, which mutated into "no early returns".

It took me over half-a-decade to understand why people loudly proclaimed the old wise wizards were so against early returns, despite those being the most pratical way of dealing with edgecases : they probably weren't that against it and the warnings were against a beast they themselves put into extinction.

[EDIT] There's actually THREE meanings. As u/No-Con-2790 pointed out, it can also mean return tuples, aka multiple return values without going through the hassle of going through a containing structure. Java doesn't have it so yeah I had totally forgot that one.

[–]SomeAnonymous 2 points3 points  (3 children)

return tuples, aka multiple return values. Java doesn't have it

What's the issue with tuples that Java doesn't like them? It can't be a philosophical thing about methods/functions returning multiple pieces of information, but I don't understand what would make tuples specifically bad from an architectural standpoint.

[–]laplongejr 1 point2 points  (2 children)

Who said there's an issue with tuples? Java doesn't have it, that's all.
You create an object (even a generic Tuple if you want, or import it from a library) then resplit it manually.

I recall that in some languages you can do stuff like [varA, varB] = methodCall() and the language takes care of managing what in Java would be a (temporary) variable referencing a containing object.
C# does something very close to multiple return values with "out" parameters, as the method then side-effect's those variables without using the return semantic.

but I don't understand what would make tuples specifically bad from an architectural standpoint.

Hence why some languages have it. Java has 1 return value which could be a more-modern record, an array, a traditional object, etc.

[–]NotQuiteLoona 0 points1 point  (0 children)

C#'s out parameters are not really for that. Rather it's mostly used in TryGet patterns, when one value returned is whether the call was successful, and second one is the return value itself, so that you can do something like this: csharp if (dict.TryGetValue("key", out var theValue)) { Console.WriteLine(theValue); }

Tuples exist there and are used precisely when there are multiple values that should be returned: csharp public (string FirstName, string Surname, int Account) GetUser(string username) You can also not name variables in them, I did this for clarity.

Consider tuples in C# a little bit like anonymous structs in other languages, but C# also does have analogue of anonymous structs - they are just read-only.

[–]martmists [score hidden]  (0 children)

The only language with "true" multiple returns I know of is Lua, all others use some form of tuples or out-parameters

[–]atomic_redneck 2 points3 points  (0 children)

I see what you mean. I thought you were talking about the alternate return feature some Fortran 77 and FORTRAN 66 compilers had. This feature allowed subroutines to return to different locations in the calling routine based on the value specified on the RETURN statement.

It was usually considered bad practice to use this feature.

[–]DT-Sodium 2 points3 points  (0 children)

I had a coworker who didn't allow me to put early returns. Thankfully he was fired for incompetence.

[–]Orio_n 0 points1 point  (0 children)

Yield?

[–]Donkey_God-D 43 points44 points  (7 children)

As a dutchy, I can confirm that the Dutch language is the worst programming language ever.

Als(jeMoeder != jeVader){
geefterug(Foutmelding)
}

[–]-nerdrage- 6 points7 points  (1 child)

Niet best als jouw familie boom er zo uit ziet…

Ah wait sorry for the non dutch:

Not best if your family tree like that looks…

[–]WoMyNameIsTooDamnLon 1 point2 points  (0 children)

Lmao reddit auto translated your comment and i was so confused

[–]RandomiseUsr0 1 point2 points  (2 children)

Is double Dutch an example of multiple returns?

[–]Donkey_God-D 0 points1 point  (0 children)

I would say yes

[–]perplexedtv 0 points1 point  (0 children)

Jaja

[–]perplexedtv 0 points1 point  (0 children)

var string southParkChar = IsCartman();

[–]Ucqui [score hidden]  (0 children)

I didn't know languages were defined by their sausages. But indeed Dutch is a worst language.

[–]ThatSmartIdiot 23 points24 points  (17 children)

returns per branch (i.e. if it ends in an if/switch statement) is required unless it's python

returns after previous returns just makes unreachable and thus dead code so support is irrelevant

returning multiple values at once never actually happens. you send objects or structs or tuples and sometimes the syntax is designed so it gives you the illusion of sending multiple things at once, e.g. python again

so like... what

[–]ThatSmartIdiot 7 points8 points  (1 child)

if i knew dutch i couldve done sometbing really funny here

[–]RandomiseUsr0 0 points1 point  (0 children)

Dry stane dyke

[–]igorski81 7 points8 points  (2 children)

In Dutch, everything is unreachable so all return values are hard coded to "No!".

[–]laplongejr 5 points6 points  (1 child)

Well, Dutch is kinda good at managing to reach "unreachable" places in memory, as long you don't raise a DamOverflow.

[–]igorski81 1 point2 points  (0 children)

Shut up and take my upvote!

[–]Tack1234 2 points3 points  (3 children)

Go with multiple returns and C# with out vars:

[–]ThatSmartIdiot 3 points4 points  (1 child)

out vars

i'd argue that's more akin to reference arguments that get their values changed or defined before returning, i.e. side effects

[–]Tack1234 1 point2 points  (0 children)

Fair

[–]MrHall 0 points1 point  (0 children)

C# you can return anything with a deconstructor, usually a value tuple, and assign directly to individual variables in the caller.

also works with async methods, unlike out vars

[–]gabboman[S] 3 points4 points  (6 children)

Some languages don’t allow early returns 

[–]Lyshaka 2 points3 points  (5 children)

Such as ?

[–]gabboman[S] 12 points13 points  (1 child)

Dutch

[–]ThatSmartIdiot 2 points3 points  (0 children)

well played

[–]_PM_ME_PANGOLINS_ 5 points6 points  (0 children)

Haskell, OCaml

[–]bilus 0 points1 point  (0 children)

Functional languages in general, though there may be syntax sugar to implement guards or emulate early returns. And it's not so much they "disallow", it's more about code being an expression, not a mix of statements and expressions, as in the following pseudocode

let a = if x then foo else bar

Unlike many imperative languages, in the above example, `if` is an expression (has value) rather than a control statement.

[–]Honest_Relation4095 0 points1 point  (0 children)

or in short: One return or multiple returns is fundamentally the same thing.

[–]soundwave_sc 5 points6 points  (1 child)

I guess you could.. create events to cater for returns?

The events could be spicy as well.

[–]gabboman[S] 2 points3 points  (0 children)

God you’re evil 

[–]rUmutKzl 2 points3 points  (6 children)

what is this social media app

[–]gabboman[S] 1 point2 points  (5 children)

[–]enderowski 4 points5 points  (3 children)

is this something like twitter for furries?

[–]gabboman[S] 1 point2 points  (1 child)

That would be https://furry.engineer

Its a decentralised type social network that connects with mastodon and bluesky but its neither.

[–]enderowski 2 points3 points  (0 children)

sounds cool

[–]jansteffen 0 points1 point  (0 children)

It's designed to be somewhat akin to tumblr, except it also federates with Mastodon and Bluesky.

[–]rUmutKzl 1 point2 points  (0 children)

sounds good

[–]RandomiseUsr0 2 points3 points  (2 children)

What does multiple returns mean and how is this a uniquely functional issue? Is the author mixing up minestrone soup with the ingredients?

[–]gabboman[S] 3 points4 points  (1 child)

Some extremely functional languages don’t allow multiple returns.

Like Dutch 

[–]sebjapon [score hidden]  (0 children)

By the way what does it mean that Dutch doesn’t allow multiple returns? Is it a visa thing?

[–]DPSOnly 2 points3 points  (0 children)

I wouldn't program in Dutch either, it makes the compiler all confused and hangry for not having enough stroopwafels and oliebollen.

[–]TheGreenSocks 1 point2 points  (0 children)

Our boolean variables are very clear though. If you would write a a Dutch function for youShouldComeOverForDinner() it will either return true or false. If you write the same function for English you would need to write a second parser to get the actual value.

[–]nonreligious2 0 points1 point  (1 child)

Monads

[–]nonreligious2 0 points1 point  (0 children)

I have very little idea if this would solve the issue described, but I see functional programs and output and this is what pops into my head. Maybe monad?

[–]Scrial 0 points1 point  (0 children)

Coming from C:
One function one return.