Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 273 lines (231 sloc) 9.422 kB
30e4276 @matthiasl 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>
11
12 <section><title>Is there a pretty printer for Erlang?</title>
13 <p>
14
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.
18
19 </p></section>
20 <section><title>Where is the source for LEEX (the erlang lexer)?</title>
21 <p>
22
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="http://forum.trapexit.org/viewforum.php?f=20">
28 trapexit</url>.
29
30 </p></section>
31 <section><title>Is there a diagram tool for Erlang?</title>
32 <p>
33
34 Not really, most people use general-purpose diagram
35 tools like <url href="http://wwwhome.cs.utwente.nl/~tcm/index.html">
36 tcm</url> or xfig. TCM, in particular, is highly recommended.
37 Some people see
38 <url href="http://www.sdl-forum.org/">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="http://www.erlang.se/euc/99/Event.ps">
43 alternative notation</url> at the Erlang User Conference 1999.
44 </p><p>
45
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 @sunny256 Update broken links to mail archive and fix link to Erlang limits
sunny256 authored
53 href="http://erlang.org/pipermail/erlang-questions/1999-March/000165.html">
30e4276 @matthiasl First commit after move to GIThub
matthiasl authored
54 mailing list archive.</url>
55 </p><p>
56
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.
64
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 @matthiasl Fixed broken links after checking all links manually
matthiasl authored
70 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
30e4276 @matthiasl 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>
74
75 The standard Erlang/OTP installation includes <em>cover</em>,
76 a test coverage tool.
77
78 </p><p>
79
80 <url href="http://www.quviq.com/">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>
87
88 <!--
89 H&aring;kan Matsson released his <url
90 href="http://www.erlang.org/~hakan/mnesia_test_3.9.2.tgz">
91 mnesia test suite</url>
92 which, by virtue of Mnesia being large, is a reasonable
93 test suite for the whole of Erlang.
94
95 REVISIT: this link was broken at last viewing -->
96
97 </p></section>
98 <section><title>Is there a way to benchmark an Erlang implementation?</title>
99 <p>
100
101 Bjorn's benchmarks are <url href="http://www.erlang.se/~bjorn/benchmarks2/">freely available</url>. The older ESTONE benchmark
102 has pretty much disappeared completely.
103
104 </p></section>
105 <section><title>Does anyone have a magic file for Erlang?</title>
106 <p>
107
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.
111
112 </p>
113 <codeinclude file="erlang_magic_file"/>
114
115 </section>
116 <section><title>Is there an Erlang IDE?</title>
117 <p>
118
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>
124
125 VI fans have several options. There is a
126 <url href="http://www.erlang.org/contrib/nedit_mode-0.9.tgz">
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="http://zanazan.am/vim/">download</url>.
131 </p><p>
132
133 There is an
134 <url href="http://sourceforge.net/projects/erlide/">Eclipse
135 plugin for Erlang</url>.
136
137 </p><p>
138 Some Windows developers use Ultraedit. Danie Schutte contributed
139 a <url href="http://www.erlang.org/download/contrib/ultraedit_erlang.zip">wordfile</url> which provides syntax highlighting.
140
141 </p><p>
142 There is an Erlang editor for NetBeans :
143 <url href="http://sourceforge.net/projects/erlybird">ErlyBird</url>
144 </p>
145
146 <p>
feb53d7 @matthiasl Added link to textmate Erlang mode
matthiasl authored
147 There is a
148 <url href="http://mac.softpedia.com/get/Developer-Tools/ErlangBBLM.shtml">BBEdit module</url>
149 </p>
150
151 <p>
152 There is a
153 <url href="http://oneless.blogspot.com/2007/04/howto-erlang-textmate-bundle.html">Textmate bundle</url>
30e4276 @matthiasl First commit after move to GIThub
matthiasl authored
154 </p>
155
156 <p>
157 There is a defunct X IDE for unix systems called "xerl". It
158 isn't worth using.
159 </p>
160
161
162 </section>
163 <section><title>Are there Erlang Coding Guidelines?</title>
164 <p>
165
166 Yes. They can be found <url
167 href="http://www.erlang.se/doc/programming_rules.shtml">
168 here</url>
169
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="http://www.erlang.org/user.html">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="http://fresh.homeunix.net/~luke/distel/">
187 homepage</url> has more information.
188
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="http://www.erlang.org/doc/man/xref.html">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="http://erlang.org/doc/apps/compiler/">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="http://www.it.uu.se/research/group/hipe/dialyzer/">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.
209
210 </p></section>
211 <section>
212 <marker id="decompiling"/>
213 <title>Is there a "reverse compiler" for BEAM files?</title>
214 <p>
215
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>
226
227 <code>
228 -module(hw).
229 -export([go/0]).
230
231 go() when true ->
232 "this is my function".
233 </code>
234
235 <p>
236 and the corresponding abstract code:
237 </p>
238 <pre>
239
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>
253
254 <p>
255
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="http://jungerl.sourceforge.net/">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.