atoms vs. integers

Ulf Wiger ulf.wiger@REDACTED
Tue Dec 9 08:12:45 CET 2003


On Tue, 9 Dec 2003 00:11:20 -0500, Shawn Pearce <spearce@REDACTED> 
wrote:

> Lennart ?hman <lennart.ohman@REDACTED> wrote:
>> Hi!
>> (a lot cut away... :-)
>> > ...
>> >What about sending these over the wire then in distributed messages to
>> >other nodes?  I'm going to use Erlang distribution rather than UBF or
>> > ...
>>
>> Try doing term_to_binary/1 on what you intend to send and you'll see 
>> what you are really sending.
>
> Thanks, that gave me what I knew it would give me.  An ei formatted
> message wherein the atom is a string.  :-)

This is almost the whole truth. If you use Distributed Erlang,
there will be an atom cache that in effect sends only references
to atoms (they have to be sent once of course.)

> I'm going to use macros, and decide this later.  I think its stupid
> to use ints here, this is why Erlang has atoms - but from a performance
> point of view, I'd be using just 1 bit in C.  :-)  I think its in the
> critical loop as far as communication goes, enough to possibly justify
> the more difficult to debug 1/2 vs. atoms 'finished'/'not_finished'.

Macros do have the advantage that you get a compile-time check
for typos etc. The disadvantage is of course, as you mention,
the slightly less descriptive debugging output, but this is more
a result of using integers rather than atoms.

I've seen macros like:

-define(true, true).

Not sure it's something I want to recommend, but it does give
you some minimal compile-time type checking.  (:

/Uffe
-- 
EAB/UPD/S Ulf Wiger
Senior System Architect, ENGINE MGW



More information about the erlang-questions mailing list