Single exit point
Orbitz - orbitz - November 18, 2005Many 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
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.
Add comment
Erlang on Twitter
» rezasur (Reza Surya): Haha makasi ya sodara ularrr ☺ RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» bagus_erlang (bagus): Marah aja kerjaan…
» jamescarr (jamescarr): Working my way through “Learn you some erlang for great good!” tonight. http://t.co/DDTJwDJO
» bagus_erlang (bagus): Capek bngt nyanyi (kemesraan)
» AngginiMaulani (Δnggini MF): Kenapa mamah jdi ngomongin erlang gini:/
» wolfeidau (Mark Wolfe): Submitted update to the #erlang package on #OpenWRT http://t.co/4Brn63XU if anyone wants to test it please ping me /cc @ErlangEmbedded
» ivansyahhsn (ivansyah): Iya dewa erlang hbd,awas ya siksamu menanti RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya
» CzarneckiD (David Czarnecki): It was like Mr. Toad’s Wild Open Source Ride here tonight: Erlang, Riak, CouchDB, Ruby and Python. #nofastpassrequired
» yang_yihming (Yiming Yang): @vw009 Which language do you often use in parallel programing? Ocaml? Erlang? C01? Or some other language?
» tengkushara (T Muni Fahtu Zahra): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
Statistics
Number of aggregated posts: 10503
Number of comments: 2137
Most recent article: May 21, 2012
Latest comments
» Erno on 100,000 Lines of Assembly Language: Excellent posting. Undoubtedly you are an expert when it comes to this writing. This is absolutely the first time I…
» Jessica on 30 September 2011: Basho Technologies, Erlang Solutions and Trifork AS Announce Big Data and NoSQL R: yeah of course. I just thought that everything will be just alright and I want to have these kind of…
» DRS786 on 25 May 2012: Poznan Erlang User Group Event: I’m going!