#scala
The return
keyword is not "optional" or "inferred"; it changes the meaning of your program, and you should never use it.
If you want to change selection, open document below and click on "Move attachment"
tpolecat
May 09, 2014
Don't Use Return in Scala
Alright, every time Martin's Coursera course runs we get people in #scala asking why they get style points taken off for using return. So here's the pro tip:
<span>The return keyword is not "optional" or "inferred"; it changes the meaning of your program, and you should never use it.
Let's look at a little example.
// Add two ints, and use this method to sum a list
def add(n:Int, m:Int): Int = n + m
def sum(ns: Int*): Int = ns.foldLeft(0)(add)
scala> sum(33, 42, Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details