Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
261 lines (219 sloc) 8.55 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>
<file>tools.xml</file>
</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>Is there an erlang formatter for CI?</title>
<p>
<url href='https://github.com/vim-erlang/vim-erlang-runtime'>
vim-erlang-runtime</url> can do that.
</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>, and also one for <c>LEX</c>
called <c>LEEX</c>. Robert Virding maintains a separate <c>LEEX</c> application,
which is available via Git on
<url href="https://github.com/rvirding/leex">GitHub</url>.
</p></section>
<section><title>Is there a diagram tool specifically for Erlang?</title>
<p>
No. Most people use general-purpose diagram
tools.
</p><p>
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>
UML-based tools never caught on in the Erlang world. Here's
a post from the <url
href="http://erlang.org/pipermail/erlang-questions/1999-March/000165.html">
mailing list archive</url> discussing some of the reasons.
</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/doc-1/man/test_server_app.html">test system</url>
for Erlang 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>
There are several open-source tools either inspired by
QuickCheck or based on similar ideas to QuickCheck, including
<url href="http://proper.softlab.ntua.gr/">Proper</url>
and <url href="https://github.com/krestenkrab/triq">Triq</url>.
</p><p>
</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>Which IDE should I use for Erlang development?</title>
<p>
Whichever you like; Erlang works with any IDE/editor which
handles plain-text files.
</p><p>
Eclipse: there is an
<url href="http://erlide.org/">Eclipse plugin for Erlang</url>.
</p><p>
Emacs: the Erlang distribution includes an Erlang mode
(in <c>lib/emacs/erlang.el</c>).
</p><p>
VIM: VIM includes a Erlang plugin. A more advanced
<url href="https://github.com/jimenezrick/vimerl">
erlang VIM plugin</url> is available on GitHub.
<c>vimerl</c> is also available via vundle, specify
<c>Bundle 'jimenezrick/vimerl'</c> in your <c>vimrc</c> and do
<c>BundleInstall</c>.
</p><p>
Ultraedit: Danie Schutte contributed
a <url href="http://www.erlang.org/download/contrib/ultraedit_erlang.zip">wordfile</url> which provides syntax highlighting.
</p><p>
NetBeans: <url href="http://sourceforge.net/projects/erlybird">ErlyBird</url>
</p>
<p>
BBEdit: a
<url href="http://code.google.com/p/erlang-bblm/">BBEdit module</url>
</p>
<p>
Textmate: a
<url href="http://oneless.blogspot.com/2007/04/howto-erlang-textmate-bundle.html">Textmate bundle</url>
</p>
<p>
IntelliJ IDEA: an
<url href="http://ignatov.github.com/intellij-erlang/">Erlang plugin</url>
</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> 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 <url href="http://www.erlang.org/doc/apps/syntax_tools/index.html">Syntax Tools Application</url> is a standard
part of Erlang.
</p><p>
<em>Distel/EMACS</em> supports refactoring and interactive debugging.
The <url href="https://github.com/massemanet/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 <url href="http://www.erlang.org/doc/apps/syntax_tools/index.html">
syntax_tools</url> application can 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>