Erlang logo

Erlang Tools

Cover

Expand All
Contract All

Table of Contents

7 Erlang Tools

7.1  Is there a pretty printer for Erlang?

If you use the emacs mode (it comes with the open source release, in lib/emacs/erlang.el), you also get a pretty printer just by printing from emacs.

7.2  Is there an erlang formatter for CI?

vim-erlang-runtime can do that.

7.3  Where is the source for LEEX (the erlang lexer)?

Erlang's libraries provide an Erlang equivalent for YACC called YECC, and also one for LEX called LEEX. Robert Virding maintains a separate LEEX application, which is available via Git on GitHub.

7.4  Is there a diagram tool specifically for Erlang?

No. Most people use general-purpose diagram tools.

Some people see SDL as the natural way of expressing telecomms problems in diagrams, while Maurice Castro presented some interesting work on an alternative notation at the Erlang User Conference 1999.

UML-based tools never caught on in the Erlang world. Here's a post from the mailing list archive discussing some of the reasons.

7.5  What code testing tools and suites exist for and in Erlang/OTP?

A test suite is especially useful for making sure that "improvements" to the system haven't broken something. The test system for Erlang can be used for testing your project and it includes test suites for the Erlang emulator and Erlang stdlib.

The standard Erlang/OTP installation includes cover, a test coverage tool.

QuickCheck is a commercial tool for automatically generating random test cases from a property written in Erlang itself. When a failing test case is detected, this test case is automatically reduced to a minimal failing case to simplify fault analysis.

There are several open-source tools either inspired by QuickCheck or based on similar ideas to QuickCheck, including Proper and Triq.

7.6  Is there a way to benchmark an Erlang implementation?

Bjorn's benchmarks are freely available. The older ESTONE benchmark has pretty much disappeared completely.

7.7  Does anyone have a magic file for Erlang?

Magic files are used on unix systems with a tool called "file" to identify files. Here's an addition to /etc/magic which allows "file" to identify BEAM and JAM files.

7.8  Which IDE should I use for Erlang development?

Whichever you like; Erlang works with any IDE/editor which handles plain-text files.

Eclipse: there is an Eclipse plugin for Erlang.

Emacs: the Erlang distribution includes an Erlang mode (in lib/emacs/erlang.el).

VIM: VIM includes a Erlang plugin. A more advanced erlang VIM plugin is available on GitHub. vimerl is also available via vundle, specify Bundle 'jimenezrick/vimerl' in your vimrc and do BundleInstall.

Ultraedit: Danie Schutte contributed a wordfile which provides syntax highlighting.

BBEdit: a BBEdit module

Textmate: a Textmate bundle

IntelliJ IDEA: an Erlang plugin

7.9  Are there Erlang Coding Guidelines?

Yes. They can be found here

7.10  What refactoring tools are there for Erlang

There are several third-party tools which help with code refactoring. They can also be used for a range of other purposes.

Syntax Tools do proper source->source transforms. Among other things they can be used to modify old code so that it no longer uses deprecated functions. The Syntax Tools Application is a standard part of Erlang.

Distel/EMACS supports refactoring and interactive debugging. The homepage has more information.

7.11  What static code analysis tools are there?

There are several tools which detect various classes of likely programming errors in Erlang code.

XREF finds all undefined module calls in a set of modules, i.e. it catches errors caused by mistyping module or function names, among others.

The Erlang Compiler has several in-built options which help detect problems. Most of these (e.g. reporting unused variables, unused functions and some classes of dead code) are enabled by default.

The Dialyzer is a dedicated static code analysis tool which examines .beam object files. Among other things, it does a global analysis and reports dead code and some classes of type error. Highly recommended.

7.12  Is there a "reverse compiler" for BEAM files?

Or: I've lost/deleted/whatever the .erl files for my project, can I somehow recreate it from the .beam files?

If the code was compiled with the debug_info flag, then the .beam file contains a 'partially compiled' representation of the source---basically the parse tree.

Here is a simple module:

     -module(hw).
     -export([go/0]).

     go() when true ->
       "this is my function".

and the corresponding abstract code:


     3> {ok, {hw, [{abstract_code, Abs}]}} =  beam_lib:chunks("hw.beam", [abstract_code]), Abs.
         {raw_abstract_v1,[{attribute,1,file,{"./hw.erl",1}},
                  {attribute,1,module,hw},
                  {attribute,2,export,[{go,0}]},
                  {function,4,
                            go,
                            0,
                            [{clause,4,
                                     [],
                                     [],
                                     [{string,5,"this is my function"}]}]},
                  {eof,6}]}

Writing a decompiler which can turn the above example back to source is a fifteen minute job. Writing a decompiler which handles more complex Erlang code is more time consuming, but not much harder. The syntax_tools application can do most of the hard work.

If the abstract code is not present in the beam file, the problem gets much harder. It is possible to study the remaining information and draw some conclusions about what the original .erl file might have looked like, for instance which functions were exported. But a lot of other important information, such as variable names, is not present. In general, recreating the source code from a beam file without abstract code is not practical.