The Overlooked Reason Why Multiple Exits are Evil

by Michael Scepaniak on October 30, 2012 in software development

Reverse Mountain and Aeolian Buttes

What do you prefer – methods with a single exit or multiple exits?

I was doing a code review the other day and noticed that the developer had coded multiple return statements (this was written in Java) into a method. I stated that I really, really didn’t like this practice, but admitted that it was simply a style preference.

It got me thinking, though. Why did I have such an aversion to it? I did some searching and found more than one discussion about the issue. In general, it appears that the majority of the debaters are fine with multiple exits (the opposite of my preference).

Regardless, I eventually found one post/answer in particular that spoke to the core of my disdain. Multiple exits weaken the maintainability of the code and invite abuse.

Paul’s answer deserves more upvotes.

Mike
Want to be notified when new articles are posted?
Enter your email address:

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post:

Member of The Internet Defense League