Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
100755 273 lines (231 sloc) 9.422 kb
30e4276 Matthias Lang First commit after move to GIThub
matthiasl authored
1 <?xml version="1.0" encoding="iso-8859-1" ?>
2 <!DOCTYPE chapter SYSTEM "chapter.dtd">
3 <chapter>
4 <header>
5 <title>Erlang Tools</title>
6 <prepared>Matthias Lang</prepared>
7 <docno></docno>
8 <date>2007-09-12</date>
9 <rev>1.0</rev>
10 </header>
12 <section><title>Is there a pretty printer for Erlang?</title>
13 <p>
15 If you use the emacs mode (it comes with the open source
16 release, in <c>lib/emacs/erlang.el</c>),
17 you also get a pretty printer just by printing from emacs.
19 </p></section>
20 <section><title>Where is the source for LEEX (the erlang lexer)?</title>
21 <p>
23 Erlang's libraries provide an Erlang equivalent for
24 <c>YACC</c> called <c>YECC</c>, but there is no equivalent
25 for <c>LEX</c>. Robert Virding wrote one called <c>LEEX</c>,
26 which is available as a 'user contribution' on
27 <url href="">
28 trapexit</url>.
30 </p></section>
31 <section><title>Is there a diagram tool for Erlang?</title>
32 <p>
34 Not really, most people use general-purpose diagram
35 tools like <url href="">
36 tcm</url> or xfig. TCM, in particular, is highly recommended.
37 Some people see
38 <url href="">SDL</url>
39 as the natural
40 way of expressing telecomms problems in diagrams,
41 while Maurice Castro presented some interesting work on an
42 <url href="">
43 alternative notation</url> at the Erlang User Conference 1999.
44 </p><p>
46 The first thing many people say is "what about Rose".
47 An Ericsson project took a look at using
48 Rose for Erlang projects, and concluded that it wasn't
49 worth using for a whole host of reasons (you can read
50 Ulf Wiger's post about an investigation into using
51 Rose as much more than just a diagram tool
52 in the <url
219e320 Øyvind A. Holm Update broken links to mail archive and fix link to Erlang limits
sunny256 authored
53 href="">
30e4276 Matthias Lang First commit after move to GIThub
matthiasl authored
54 mailing list archive.</url>
55 </p><p>
57 The essential reason for Rose and such not looking
58 promising for use with Erlang is that the way you model
59 a problem in Erlang is rather different to the way you
60 decompose a problem with OO. While you're worrying about
61 processes, gen_servers, asynchronous messages and supervision
62 trees the tool wants to help you with singletons, exceptions,
63 threads and templates.
65 </p></section>
66 <section><title>What code testing tools and suites exist for and in Erlang/OTP?</title>
67 <p>
68 A test suite is especially useful for making sure that
69 "improvements" to the system haven't broken something.
1f7e8d2 Matthias Lang Fixed broken links after checking all links manually
matthiasl authored
70 The <url href="">test system</url> for Erlang. The test server can be used for testing
30e4276 Matthias Lang First commit after move to GIThub
matthiasl authored
71 your project and it includes test suites for the Erlang emulator
72 and erlang stdlib.
73 </p><p>
75 The standard Erlang/OTP installation includes <em>cover</em>,
76 a test coverage tool.
78 </p><p>
80 <url href="">QuickCheck</url> is a
81 commercial tool for automatically generating
82 random test cases from a property written in Erlang
83 itself. When a failing test case is detected, this test case
84 is automatically reduced to a minimal failing case to simplify
85 fault analysis.
86 </p><p>
88 <!--
89 H&aring;kan Matsson released his <url
90 href="">
91 mnesia test suite</url>
92 which, by virtue of Mnesia being large, is a reasonable
93 test suite for the whole of Erlang.
95 REVISIT: this link was broken at last viewing -->
97 </p></section>
98 <section><title>Is there a way to benchmark an Erlang implementation?</title>
99 <p>
101 Bjorn's benchmarks are <url href="">freely available</url>. The older ESTONE benchmark
102 has pretty much disappeared completely.
104 </p></section>
105 <section><title>Does anyone have a magic file for Erlang?</title>
106 <p>
108 Magic files are used on unix systems with a tool called "file" to identify
109 files. Here's an addition to /etc/magic which allows "file" to identify
110 BEAM and JAM files.
112 </p>
113 <codeinclude file="erlang_magic_file"/>
115 </section>
116 <section><title>Is there an Erlang IDE?</title>
117 <p>
119 The "official" development environment for Erlang is Emacs,
120 and there's a special emacs mode for Erlang. This can be
121 found in <c>lib/emacs/erlang.el</c> under the
122 source tree.
123 </p><p>
125 VI fans have several options. There is a
126 <url href="">
127 colouring mode for nedit</url>. VIM has a fully-fledged Erlang
128 mode. A basic version is included in VIM as of version 5.6, a
129 much more complete version is available for
130 <url href="">download</url>.
131 </p><p>
133 There is an
134 <url href="">Eclipse
135 plugin for Erlang</url>.
137 </p><p>
138 Some Windows developers use Ultraedit. Danie Schutte contributed
139 a <url href="">wordfile</url> which provides syntax highlighting.
141 </p><p>
142 There is an Erlang editor for NetBeans :
143 <url href="">ErlyBird</url>
144 </p>
146 <p>
feb53d7 Matthias Lang Added link to textmate Erlang mode
matthiasl authored
147 There is a
148 <url href="">BBEdit module</url>
149 </p>
151 <p>
152 There is a
153 <url href="">Textmate bundle</url>
30e4276 Matthias Lang First commit after move to GIThub
matthiasl authored
154 </p>
156 <p>
157 There is a defunct X IDE for unix systems called "xerl". It
158 isn't worth using.
159 </p>
162 </section>
163 <section><title>Are there Erlang Coding Guidelines?</title>
164 <p>
166 Yes. They can be found <url
167 href="">
168 here</url>
170 </p></section>
171 <section><title>What refactoring tools are there for Erlang</title>
172 <p>
173 There are several third-party tools which help with
174 code refactoring. They can also be used for a range of
175 other purposes.
176 </p><p>
177 <em>Syntax Tools</em>Richard Carlsson's syntax tools do
178 proper source->source transforms. Among other things they
179 can be used to modify old code so that it no longer uses
180 deprecated functions. It is available on the
181 <url href="">user contributions
182 page</url>
183 </p><p>
184 <em>Distel/EMACS</em> is an EMACS monstrosity
185 with support for refactoring and interactive debugging.
186 The <url href="">
187 homepage</url> has more information.
189 </p></section>
190 <section><title>What static code analysis tools are there?</title>
191 <p>
192 There are several tools which detect various classes of
193 likely programming errors in Erlang code.
194 </p><p>
195 <url href="">XREF</url>
196 finds all undefined module calls in a set of modules, i.e.
197 it catches errors caused by mistyping module or function names,
198 among others.
199 </p><p>
200 The <url href="">Erlang Compiler</url> has several in-built options
201 which help detect problems. Most of these (e.g. reporting unused
202 variables, unused functions and some classes of dead code) are
203 enabled by default.
204 </p><p>
205 The <url href="">Dialyzer</url> is a dedicated static code analysis
206 tool which examines .beam object files. Among other things,
207 it does a global analysis and reports dead code and
208 some classes of type error. Highly recommended.
210 </p></section>
211 <section>
212 <marker id="decompiling"/>
213 <title>Is there a "reverse compiler" for BEAM files?</title>
214 <p>
216 Or: I've lost/deleted/whatever the .erl files for my project,
217 can I somehow recreate it from the .beam files?
218 </p><p>
219 <em>If</em> the code was compiled with
220 the <c>debug_info</c> flag, then the .beam file
221 contains a 'partially compiled' representation of the
222 source---basically the parse tree.
223 </p><p>
224 Here is a simple module:
225 </p>
227 <code>
228 -module(hw).
229 -export([go/0]).
231 go() when true ->
232 "this is my function".
233 </code>
235 <p>
236 and the corresponding abstract code:
237 </p>
238 <pre>
240 3> {ok, {hw, [{abstract_code, Abs}]}} = beam_lib:chunks("hw.beam", [abstract_code]), Abs.
241 {raw_abstract_v1,[{attribute,1,file,{"./hw.erl",1}},
242 {attribute,1,module,hw},
243 {attribute,2,export,[{go,0}]},
244 {function,4,
245 go,
246 0,
247 [{clause,4,
248 [],
249 [],
250 [{string,5,"this is my function"}]}]},
251 {eof,6}]}
252 </pre>
254 <p>
256 Writing a decompiler which can turn the above example back to source
257 is a fifteen minute job. Writing a decompiler which handles more
258 complex Erlang code is more time consuming, but not much harder.
259 The <c>syntax_tools</c> package from the
260 <url href="">jungerl</url>
261 can be used to do most of the hard work.
262 </p><p>
263 If the abstract code is <em>not</em> present in the
264 beam file, the problem gets much harder. It is possible to study
265 the remaining information and draw some conclusions about what
266 the original .erl file might have looked like, for instance which
267 functions were exported. But a lot of other important information,
268 such as variable names, is not present. In general, recreating the
269 source code from a beam file without abstract code is not practical.
270 </p>
271 </section>
272 </chapter>
Something went wrong with that request. Please try again.