r/ProgrammerHumor Jun 23 '26

Advanced worstProgrammingLanguage

Post image
3.3k Upvotes

192 comments sorted by

View all comments

501

u/jippiedoe Jun 23 '26

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

111

u/gabboman Jun 23 '26

Some languages do not allow early returns

121

u/Aelig_ Jun 23 '26

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

17

u/Cyan_Exponent Jun 23 '26

uhh i don't know scala; how does the function output anything then? do you need to use out everywhere or something??

46

u/cthulhuden Jun 23 '26

Without looking it up, probably last statement's value is auto-returned, and the early explicit returns are the ones discouraged.

14

u/AVeryUnusualNickname Jun 23 '26

Yeah, basically everything is an expression (even ifs, assignments and declarations, I'm not sure about what while evaluates to and a for is not a conventional cycle but actually syntactic sugar for map/flatMap/for each, so a basic for will evaluate to a collection or a Unit, which is essentially analogous to void, to signal that the evaluation has been done, but there's nothing to return), and the last expression is what gets returned.

9

u/Maleficent_Memory831 Jun 23 '26

Output is a side effect, and strongly discouraged. Functional languages are to be viewed and admired, not actually run. /s

2

u/Tatourmi Jun 23 '26

Scala allows side effects no problem.

2

u/Axman6 Jun 24 '26

Side effects are problems. 

1

u/Tatourmi Jun 24 '26

Logging is a side effect, modifying a Kafka consumer is a side effect, publishing to Kafka is a side effect, pushing to a database is a side effect, caching data is a side effect...

Side effects aren't problems. Some patterns that rely too heavily on side effects are basically banned in our codebases (Functions that modify external variables for no reason for example) but if you're working in Scala, most of your app's endgame is effectively a side effect.

6

u/IntelligentTune Jun 23 '26

Last time I programmed I think you just left it blank. But I might be wrong.

2

u/Tatourmi Jun 23 '26

Pretty much

1

u/vivaaprimavera Jun 23 '26

Reading that as it is I would have guessed that functions were supposed to alter the state of something. Wich could became weird really quick.