atoms vs. integers
Tue Dec 9 23:36:24 CET 2003
Ulf Wiger <ulf.wiger@REDACTED> wrote:
> >>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.)
Ah, well, if the distribution protocol is that smart, then I guess
atoms aren't really all that much slower than ints, once you get them
sent over the first time. That being the case, using atoms is better
than using ints, just for the sake of making it easier to write and
debug the code, especially once in production when lots of things are
This comment was what I was hoping to hear, thank you Ulf.
> >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).
That'll work assuming one says ?true rather than true in the code. So
easy to get it wrong!
Yea, I'm not too big on the macros myself to just hide the atoms. I
think its pretty silly. On the other hand, it makes it easy to switch
from int to atom and back.
More information about the erlang-questions