[erlang-questions] suggestion: shorthand functions

Ulf Wiger ulf@REDACTED
Fri Jan 11 15:54:08 CET 2013


On 11 Jan 2013, at 15:18, Raimo Niskanen wrote:

> I think it is a nice idea that would improve scripting.
> 
> But how to agree on module names and content is harder. There is a limited
> number of 1 and 2 character module names, and once in OTP they are written
> in stone.

This is true.

I don't think keeping the module names within 2 characters is a 
top priority. Actually, 'file' is just fine, but the functions in file
consistently return {ok,V} | {error, R}, so mixing it up in there
has its disadvantages. 

OTOH, once you string together a few calls to 
filename:basename/1 and filename:dirname/1 inside a call 
to filename:join/2, 80 character line width doesn't seem
like much. :)

> For f.erl I miss e.g is_dir from filelib, which would introduce the notion
> of merging old module functionality. Using the name 'fl' for filelib
> functions would just be hard to remember.

I also thought about adding is_dir/1, is_file/1, is_symlink/1, but didn't
partly because I had other things to do, and partly because I started
thinking about how the semantics of the original functions is the right
one anyway…

When I added the module fn, it was mainly because e.g. adding 
join/2 to f.erl might seem unintuitive, as we're not joining files, but
filenames. OTOH, the functions in filelib could be mapped to f.erl,
I think.


> Aliasing filename:basename to fn:base is a bit unintuitive since the
> original Unix command is called 'basename' and for e.g file:list_dir
> you have aliased it to f:ls (as for many other) to make them more Unix:ish.
> I think it would be better to keep to unix command names where possible.
> [Wild idea: f:'-d' for filelib:is_dir, or t:'-d', or f:test(d, Path).]

Agree.

> An alternative approach might be to have a helper module named 'es'
> containing all scripting aliases…

That's an idea, but on the other hand, the functions may well 
catch on outside of scripting too, among those who prefer the 
let-it-fail semantics.

BR,
Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list