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

Bengt Kleberg bengt.kleberg@REDACTED
Thu Jun 4 12:08:40 CEST 2009


Greetings,

The thought of getting a new standard library with less clutter and
inconsistency is very welcome. So that, alone , makes this is a good
idea. Presumably there are a lot of other good things in this suggestion
since it comes from Joe. However, I must have missed them since I can
not help but think that the benefits presented are not enough.

1) I would still need to look in the documentation. No longer to find
the position, but to find out the names/spelling of the arguments. Is it
string: or str:, start: or first: and is it length: or chars:?

2) I do not find it more beneficial to write
string:substring( string:S start:I length:J ), instead of
string:substring( String, Start, Length ).


bengt

On Thu, 2009-06-04 at 11:10 +0200, Joe Armstrong wrote: 
> I've been writing some objective-C and like the method calling syntax.
> Objective-C (and smalltalk) code is very readable without lot's of comments
> 
> Could we do something similar in Erlang?
> This was (I think)  discussed a long time ago but can't find the discussion.
> 
> Imagine a function like string:substring/3. A call to this looks like:
> 
>         string:substring(Str, I, J)
> 
> The problem with this is that it's difficult to remember the argument order
> and you have to consult the documentation *to find out the order of
> the arguments*
> I *know* what the arguments are (a string, a start index and a length)
> but I have to
> consult the documentation to find the order.
> 
> Solution: write the call like this.
> 
>        string:substring( string:S start:I length:J)
> 
> This could be expanded into a canonical form:
> 
>        string:substring_start_string_length(S, I, J)
> 
> where the tags are sorted.
> 
> This would also make the definitions of functions *shorter*
> and almost self-documenting
> 
> 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).
> 
> whose canonical expansion is:
> 
>      f123_filename_mode(F, M) ->
>                 Fin = F ++ ".erl",
>                 Fout = F++ ".beam",
>                 compile(Fin, Fout, M).
> 
> This change has many advantages:
> 
>             + forces use of meaningful tag names in arguments
>             + don't have to remember argument order
>             + variable names in the body of a function become shorter
> 
> 
> If we were to make this change we would have to rewrite all the
> standard libraries
> but this would be a *good thing* - since this time we could get them right.
> 
> This is would also be a backwards compatible change (I think)
> 
>  /Joe
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
> 



More information about the erlang-questions mailing list