Single exit point

Orbitz - orbitz - November 18, 2005

Many programmers insist on only having the flow of control in their function end at a single point.  I got wondering for a few minutes if any languages enforce this style of programming.  Then I realized.  Erlang has no ‘return’ operator, so doesn’t Erlang enforce this?  That sounds about right as far as I can see.  So an Erlang function can only have 1 exit point.  That should make them feel good.


But as was just pointed out to me in the middle of writing this, Erlang has ‘throw’.  There can be many of thoughs.  So perhaps Erlang doesn’t have 1 exit point.

On a final note:
Does having 1 exit point even matter? Who cares?  The beauty of Erlang (in my opinion) is it almost forces you to write short concise functions.  Every single one of my erlang functions fits on 1 screen easily, so does having multiple exit locations from there matter? In my opinion, no.  I don’t need to go searching through pages of code for that function to find it, I can see it, so who cares?



Categories: Blogs  Orbitz  

Comments

anonymous avatar

Nearly right - everything in tail position is a return point. It is fairly easy to determine those points - though I have occasionally found myself wishing that my IDE (well, Emacs) could highlight them.

Functions with multiple clauses are a special case of functions with multiple tail positions; these quite clearly have multiple return points.
Indeed, one of the uses for multiple clauses is where in an imperative language you’d use an early return.

Posted by Erik Søe Sørensen on 26 Oct 2011 at 20:15



 


Add comment

Name:

Email:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?