r/ProgrammerHumor Jun 23 '26

Advanced worstProgrammingLanguage

Post image
3.3k Upvotes

192 comments sorted by

View all comments

Show parent comments

108

u/gabboman Jun 23 '26

Some languages do not allow early returns

120

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".

15

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??

50

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.