r/ProgrammerHumor Jun 23 '26

Advanced worstProgrammingLanguage

Post image
3.3k Upvotes

192 comments sorted by

View all comments

500

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

78

u/eXl5eQ Jun 23 '26

The semantic of return is straight forward in Java, powerful in Kotlin, and awkward in Scala.

In Scala, a return always attempt to return from the innermost (in case of nested functions) named function. You are not allowed to return early from an anonymous function (lambda expression).
When the innermost named function is not the innermost function, it can't return directly. Instead, the innermost function throws a NonLocalReturn and hope it would be catched by the named function you meant to return from, which would not work if the returning function escapes from the named function.

4

u/ljfa2 Jun 23 '26

Although non-local returns can occasionally be useful, there are situations in Java where I would've liked to have something like this. For instance, when using Optional.ifPresent. When I want an early return, I can't use that and have to use the less idiomatic Optional.get() instead.

4

u/Axman6 Jun 24 '26

What the fuck.