Learning by reading code

Ulf Wiger etxuwig@REDACTED
Tue May 27 13:32:43 CEST 2003

On Tue, 27 May 2003, WILLIAMS Dominic wrote:

>I am trying to learn Erlang, and like to read code written
>by experienced Erlangers.

I think this is good, and I notice that you've been reading
my code. Hopefully, you will also keep in mind that
experienced programmers do not always set good examples. ;)

>I came across the following things (in xmerl) for which I
>could find no explanation in the documentation:

Apologies for the insufficient documentation.


>What does this mean? Does it automatically export all
>functions contained in the file?

Yes. It's a common way to start out when writing code. It
means that you can easily call all functions in a compiled
module from the shell. This makes it a lot easier to test
your code.

Normally, you're supposed to remove the -compile(export_all)
and specifically export only the functions that should be
exported. This is not always done. (:

>'#text'(Text) ->
>    export_text(Text).
>There are lots of functions in xmerl with these funny
>names. Does this have any special significance?

These appear in callback modules for exporting XML
structures (e.g. as HTML or XML text). The '#' is "namespace
management", identifying the functions as special control
functions. All other exported functions in such a module are
supposed to signify XML tags (i.e. the function name matches
the XML tag. Since '#text' is not a valid XML tag, there can
be no name clash.

Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes

More information about the erlang-questions mailing list