This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Sanity of "return"

1 reply
Andrés Testi
Joined: 2009-01-22,
User offline. Last seen 42 years 45 weeks ago.

Is using return statements considered bad practice?
Regards.

- Andrés

James Iry
Joined: 2008-08-19,
User offline. Last seen 1 year 23 weeks ago.
Re: Sanity of "return"
Using return is usually, but not always, a code smell in Scala - something that indicates that you're doing something that could be written more clearly in a more expression oriented way or with some nested functions or whatever.  As always there are exceptions where return make sense.  For instance, if you use a while loop in a certain bit of performance critical code then you may need to jump out early and return might be clearer than adding extra condition checks.  On the other hand, if that kind of code is common for you then it might be that you're trying to pound a Scala shaped peg into a Java or even C shaped hole.

On Tue, Mar 3, 2009 at 6:43 PM, Andrés Testi <andres.a.testi@gmail.com> wrote:
Is using return statements considered bad practice?
Regards.

- Andrés

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland