[erlang-questions] Reassigning variables

Johnny Billquist bqt@REDACTED
Tue Mar 17 22:53:21 CET 2009

Matthew Dempsky wrote:
> On Tue, Mar 17, 2009 at 1:38 PM, Justin Sheehy <justin@REDACTED> wrote:
>> Single assignment is one of the biggest ways in which Erlang helps
>> reduce bugs.  Please don't try to introduce ways around it, as they
>> will make programs worse.
> I disagree.  There are ways that reassignment can make code easier to
> analyze, but I'm not suggesting people use reassignment in those
> cases.
> Similarly, Erlang doesn't support 'return', but our ad server has
> enough business logic where the code would be much simpler if it did.
> We had some code that was effectively:
>     if requested ad size is bad:
>         return {skip, bad_size}
>     if the game has ads disabled:
>         return {skip, disabled}
>     if the game is filtering a domain:
>         return {skip, domain_filtered}
>     return choose_ad()
> I rewrote this code in 'Erlang style' with a list of funs to check,
> and to short-circuit on the first that returns a skip, when I last
> added to it, and so incrementally it's much less work to add new
> checks than the old code.

Huh? What's wrong with coding that in Erlang as:

foo() ->
     requested ad size is bad ->
       {skip, bad_size};
     the game has ads disabled ->
       {skip, disabled};
     the game is filtering a domain ->
       {skip, domain_filtered};
     _ ->


Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt@REDACTED             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol

More information about the erlang-questions mailing list