Thursday, March 01, 2001 ..:: Home ::.. Register  Login
   TechTidBits (Blog)  

Series: Coding Contentions: How do you return?

Aug 27

Written by:
Wednesday, August 27, 2008 1:32 PM  RssIcon

As you're processing a method, how do you return back to the calling method?  Do you have multiple returns in your logic or just have one at the end of the method?

After high-school, I got used to writting one and only one return statement at the end of a method.  I was told it was bad practise to have multiple returns "littered throughout your method."   And you/we were graded that way, multiple returns meant less marks, you quickly learned to bend to "da man."

However, after a few years (ok, stop laughing, it's been a bit more than a few :>) and a few languages (VB, Java, C#), I've seen many high profile programmers using both multiple returns and single returns.  I've even seen it debated online but those URLs escapse me at the moment.

What is part of your coding standards?  Do you have any standards for this type of thing?  Take a look at your existing code and tell me what you're using now.  I would love to read what other people are using/doing!

If you don't know what I'm talking about, here's a sample doing both.

Single and Multiple Returns in methods

Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Add Comment   Cancel 
Copyright 1999-2012 by   Terms Of Use  Privacy Statement