Why does Scala require functions to have explicit return type?
Posted
by
garbage collection
on Programmers
See other posts from Programmers
or by garbage collection
Published on 2012-10-03T03:15:22Z
Indexed on
2012/10/03
3:50 UTC
Read the original article
Hit count: 157
functional-programming
|scala
I recently began learning to program in Scala, and it's been fun so far. I really like the ability to declare functions within another function which just seems to intuitive thing to do.
One pet peeve I have about Scala is the fact that Scala requires explicit return type in its functions. And I feel like this hinders on expressiveness of the language. Also it's just difficult to program with that requirement. Maybe it's because I come from Javascript and Ruby comfort zone. But for a language like Scala which will have tons of connected functions in an application, I cannot conceive how I brainstorm in my head exactly what type the particular function I am writing should return with recursions after recursions.
This requirement of explicit return type declaration on functions, do not bother me for languages like Java and C++. Recursions in Java and C++, when they did happen, often were dealt with 2 to 3 functions max. Never several functions chained up together like Scala.
So I guess I'm wondering if there is a good reason why Scala should have the requirement of functions having explicit return type?
© Programmers or respective owner