[erlang-questions] suggestion: shorthand functions
Fri Jan 11 15:18:54 CET 2013
On Fri, Jan 11, 2013 at 10:12:40AM +0100, Ulf Wiger wrote:
> Since I've been writing a bunch of rebar.config.script code lately,
> I've suffered the agony of trying to write concise and readable
> code without having to do tons of copy-paste, weird unwrapping
> funs etc.
> What I think would make this sort of thing easier, and also
> escript programming in general, is if OTP could provide some
> modules with concise naming and let-it-fail semantics.
> Just off the top of my head, I scribbled down a few functions that
> I think would make *my* life easier. I pushed them to github to
> get some discussion going.
> The modules are:
> f.erl - shorthand functions for file.erl
> fn.erl - ditto for filename.erl
> e.erl - ditto for erl_eval.erl
> The least beneficial is perhaps filename:erl, but my fingers and
> eyes ache from all the filename:join(filename:dirname(F), …)
> Otherwise, I think the biggest benefit is to stick to let-it-crash
> programming, which I find is usually the default when I write
> scripts. The original functions are always available if you want
> to take a closer look at return values.
> (For the file:script() counterparts, I also always pass the name
> of the script as a binding).
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
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.
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).]
An alternative approach might be to have a helper module named 'es'
containing all scripting aliases...
> Ulf W
> Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions