[ANN] erl_aliases -- parse transformation for shortening record and module names

Anton Lavrik alavrik@REDACTED
Tue Dec 28 04:03:02 CET 2010


Hi all,

I'm pleased to announce a tool for shortening long record and module names.

Global record and module names tend to be relatively long. While long
names are more descriptive and help to keep names unique across
different applications, they can be cumbersome inside application
code. For instance, it is fairly annoying to type a long record name
every time just to access a field. It also makes code look more
cluttered.

Erl_aliases provides a simple and straightforward interface for
defining aliases for record and module names. Once defined, aliases
can be used instead of the original names.

Usage example:

    % register a parse transformation
    -include_lib("erl_aliases.hrl").
    ...
    -record(long_record_name, {...}).
    ...
    % define alias 'r' for the previously defined record 'long_record_name':
    -record_alias({r, long_record_name}).
    ...
    % define alias 'm' for module 'long_module_name':
    -module_alias({m, long_module_name}).

Now one can use 'r' instead of 'long_record_name' and 'm' instead
'long_module_name' in all appropriate contexts.

It works by traversing the input AST and renaming aliases appearing in
their valid contexts back to the original names.

The source code and more detailed description is available on GitHub:
https://github.com/alavrik/erl_aliases

Enjoy!

Anton


More information about the erlang-questions mailing list