Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 273 lines (231 sloc) 9.422 kb
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<title>Erlang Tools</title>
<prepared>Matthias Lang</prepared>
<docno></docno>
<date>2007-09-12</date>
<rev>1.0</rev>
</header>
<section><title>Is there a pretty printer for Erlang?</title>
<p>
If you use the emacs mode (it comes with the open source
release, in <c>lib/emacs/erlang.el</c>),
you also get a pretty printer just by printing from emacs.
</p></section>
<section><title>Where is the source for LEEX (the erlang lexer)?</title>
<p>
Erlang's libraries provide an Erlang equivalent for
<c>YACC</c> called <c>YECC</c>, but there is no equivalent
for <c>LEX</c>. Robert Virding wrote one called <c>LEEX</c>,
which is available as a 'user contribution' on
<url href="http://forum.trapexit.org/viewforum.php?f=20">
trapexit</url>.
</p></section>
<section><title>Is there a diagram tool for Erlang?</title>
<p>
Not really, most people use general-purpose diagram
tools like <url href="http://wwwhome.cs.utwente.nl/~tcm/index.html">
tcm</url> or xfig. TCM, in particular, is highly recommended.
Some people see
<url href="http://www.sdl-forum.org/">SDL</url>
as the natural
way of expressing telecomms problems in diagrams,
while Maurice Castro presented some interesting work on an
<url href="http://www.erlang.se/euc/99/Event.ps">
alternative notation</url> at the Erlang User Conference 1999.
</p><p>
The first thing many people say is "what about Rose".
An Ericsson project took a look at using
Rose for Erlang projects, and concluded that it wasn't
worth using for a whole host of reasons (you can read
Ulf Wiger's post about an investigation into using
Rose as much more than just a diagram tool
in the <url
href="http://erlang.org/pipermail/erlang-questions/1999-March/000165.html">
mailing list archive.</url>
</p><p>
The essential reason for Rose and such not looking
promising for use with Erlang is that the way you model
a problem in Erlang is rather different to the way you
decompose a problem with OO. While you're worrying about
processes, gen_servers, asynchronous messages and supervision
trees the tool wants to help you with singletons, exceptions,
threads and templates.
</p></section>
<section><title>What code testing tools and suites exist for and in Erlang/OTP?</title>
<p>
A test suite is especially useful for making sure that
"improvements" to the system haven't broken something.
The <url href="http://www.erlang.org/project/test_server/index.html">test system</url> for Erlang. The test server can be used for testing
your project and it includes test suites for the Erlang emulator
and erlang stdlib.
</p><p>
The standard Erlang/OTP installation includes <em>cover</em>,
a test coverage tool.
</p><p>
<url href="http://www.quviq.com/">QuickCheck</url> 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.
</p><p>
<!--
H&aring;kan Matsson released his <url
href="http://www.erlang.org/~hakan/mnesia_test_3.9.2.tgz">
mnesia test suite</url>
which, by virtue of Mnesia being large, is a reasonable
test suite for the whole of Erlang.
REVISIT: this link was broken at last viewing -->
</p></section>
<section><title>Is there a way to benchmark an Erlang implementation?</title>
<p>
Bjorn's benchmarks are <url href="http://www.erlang.se/~bjorn/benchmarks2/">freely available</url>. The older ESTONE benchmark
has pretty much disappeared completely.
</p></section>
<section><title>Does anyone have a magic file for Erlang?</title>
<p>
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.
</p>
<codeinclude file="erlang_magic_file"/>
</section>
<section><title>Is there an Erlang IDE?</title>
<p>
The "official" development environment for Erlang is Emacs,
and there's a special emacs mode for Erlang. This can be
found in <c>lib/emacs/erlang.el</c> under the
source tree.
</p><p>
VI fans have several options. There is a
<url href="http://www.erlang.org/contrib/nedit_mode-0.9.tgz">
colouring mode for nedit</url>. VIM has a fully-fledged Erlang
mode. A basic version is included in VIM as of version 5.6, a
much more complete version is available for
<url href="http://zanazan.am/vim/">download</url>.
</p><p>
There is an
<url href="http://sourceforge.net/projects/erlide/">Eclipse
plugin for Erlang</url>.
</p><p>
Some Windows developers use Ultraedit. Danie Schutte contributed
a <url href="http://www.erlang.org/download/contrib/ultraedit_erlang.zip">wordfile</url> which provides syntax highlighting.
</p><p>
There is an Erlang editor for NetBeans :
<url href="http://sourceforge.net/projects/erlybird">ErlyBird</url>
</p>
<p>
There is a
<url href="http://mac.softpedia.com/get/Developer-Tools/ErlangBBLM.shtml">BBEdit module</url>
</p>
<p>
There is a
<url href="http://oneless.blogspot.com/2007/04/howto-erlang-textmate-bundle.html">Textmate bundle</url>
</p>
<p>
There is a defunct X IDE for unix systems called "xerl". It
isn't worth using.
</p>
</section>
<section><title>Are there Erlang Coding Guidelines?</title>
<p>
Yes. They can be found <url
href="http://www.erlang.se/doc/programming_rules.shtml">
here</url>
</p></section>
<section><title>What refactoring tools are there for Erlang</title>
<p>
There are several third-party tools which help with
code refactoring. They can also be used for a range of
other purposes.
</p><p>
<em>Syntax Tools</em>Richard Carlsson's 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. It is available on the
<url href="http://www.erlang.org/user.html">user contributions
page</url>
</p><p>
<em>Distel/EMACS</em> is an EMACS monstrosity
with support for refactoring and interactive debugging.
The <url href="http://fresh.homeunix.net/~luke/distel/">
homepage</url> has more information.
</p></section>
<section><title>What static code analysis tools are there?</title>
<p>
There are several tools which detect various classes of
likely programming errors in Erlang code.
</p><p>
<url href="http://www.erlang.org/doc/man/xref.html">XREF</url>
finds all undefined module calls in a set of modules, i.e.
it catches errors caused by mistyping module or function names,
among others.
</p><p>
The <url href="http://erlang.org/doc/apps/compiler/">Erlang Compiler</url> 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.
</p><p>
The <url href="http://www.it.uu.se/research/group/hipe/dialyzer/">Dialyzer</url> 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.
</p></section>
<section>
<marker id="decompiling"/>
<title>Is there a "reverse compiler" for BEAM files?</title>
<p>
Or: I've lost/deleted/whatever the .erl files for my project,
can I somehow recreate it from the .beam files?
</p><p>
<em>If</em> the code was compiled with
the <c>debug_info</c> flag, then the .beam file
contains a 'partially compiled' representation of the
source---basically the parse tree.
</p><p>
Here is a simple module:
</p>
<code>
-module(hw).
-export([go/0]).
go() when true ->
"this is my function".
</code>
<p>
and the corresponding abstract code:
</p>
<pre>
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}]}
</pre>
<p>
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 <c>syntax_tools</c> package from the
<url href="http://jungerl.sourceforge.net/">jungerl</url>
can be used to do most of the hard work.
</p><p>
If the abstract code is <em>not</em> 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.
</p>
</section>
</chapter>
Jump to Line
Something went wrong with that request. Please try again.