[erlang-questions] erlang improvement - objective c (or smalltalk) syntax

Dominic Williams erlang@REDACTED
Thu Jun 4 11:35:39 CEST 2009


Hi,

Joe Armstrong a écrit :
> ie: today I might write something
> 
>          f123(FileName, Mode) ->
>                 Fin = FileName ++ ".erl",
>                 Fout = FileName ++ ".beam",
>                 compile(Fin, Fout, Mode).
> 
> whereas I could write
> 
>          f123(filename:F mode:M) ->
>                 Fin = F ++ ".erl",
>                 Fout = F++ ".beam",
>                 compile(Fin, Fout, M).

Notice how you did *not* write:

           f123(filename:FileName mode:Mode) ->
                  Fin = FileName ++ ".erl",
                  Fout = FileName++ ".beam",
                  compile(Fin, Fout, Mode).

because with your suggestion the tags and the variable names 
carry the same information and become redundant. This is 
exactly the same weakness as static typing, where you get 
semantic duplication, e.g. this sort of thing is common in Java:

FileName fileName = new FileName("myfile");

So in your example you reduced the variable name to a single 
letter, which I cannot see as an improvement in readability.

In addition to that, I think your suggestion replaces the 
problem of remembering the order of arguments with the 
problem of remembering all the tags. One may argue that in a 
well written library with consistent tag names, that would 
be easier, but the same is true of argument order: it would 
be easier to remember if it were consistent (which is not 
the case e.g. in the lists module some functions that 
operate on a single list take the list first, some take it 
last, in dict the dict always comes last, in file the 
filename always comes first...)

Regards,

Dominic Williams
http://dominicwilliams.net


More information about the erlang-questions mailing list