[erlang-questions] Reassigning variables

Angel Alvarez clist@REDACTED
Sat Mar 21 00:11:05 CET 2009

Hi all

El Martes, 17 de Marzo de 2009 Matthew Dempsky escribió:
> 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.
> But it's stupid.  I'm not going to add 100 new checks, there's only a
> handful now, and there will almost certainly never be more than a
> handful more in the future.  Rewriting 10 lines of code to be 60 lines
> of code (having to define a new function for each check, having to add
> code to handle the list of check funs, etc.) to deal with Erlang's
> language limitations does not help with readability.

¿Maybe it can be acomplished using a list of funs?

The averall return code can be seen as a fold over the list of Funs for any given argument...

being newbie on erlang issues, i cant show you such code but all you can imagine what 
im trying to say..

Regards , Angel

> (In contrast, we similarly redesigned the per-campaign and per-ad
> filtering code to use this style, and they do update much more
> frequently, and it actually has been beneficial allowing us to
> dynamically change what lists of filters are applied in different
> situations.  But not everything merits that complexity.)
> Programmers understand how variable reassignment and multiple function
> call returns work: every beginner programming language includes them.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

Este correo no tiene dibujos. Las formas extrañas en la pantalla son letras.
    Clist UAH a.k.a Angel

No le daría Cocacola Zero, ni a mi peor enemigo. Para eso está el gas Mostaza que es mas piadoso.

More information about the erlang-questions mailing list