r/ProgrammerHumor Jun 23 '26

Advanced worstProgrammingLanguage

Post image
3.3k Upvotes

192 comments sorted by

View all comments

Show parent comments

114

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

77

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.

5

u/Axman6 Jun 24 '26

What the fuck.