Erlang Idioms - A Pattern for an Erlang Programming Team

Steve Davis <>
Sat Feb 13 01:59:01 CET 2010


If I were to contribute one idiom, it would be that encoding all text
as binaries improves your programs enormously.

While it may appear troublesome to type <<"hello">> rather than
"hello", the rewards in later manipulation is extreme.

"Strings are just lists of integers" runs into irreconcilable problems
when you consider that [0,1,2,3,4,5] could be a "string", should you
decide to define a character encoding such that "s" = 0, "t" = 1, "i"
= 2, etc.

Matching on text presented as lists quickly leads to code bloat and
headaches in the parts of your code that detect and manipulate text. I
have found that when rigorously sticking to text encoded as binaries
in my programs, it leads to far cleaner, shorter and more
understandable functions.

I would go as far as to say that the combination of: the re module +
binary matching + binary text ...make Erlang far *superior* in text
manipulation than any other language I have ever used (caveat: that's
quite a few languages but by no means all).

I have found this true even when coding for text-based protocols such
as http. It has even led me to consider whether the reason why http
became ubiquitous is because it removes the the ambiguity of the
string concept in most (all?) languages, because in http everything is
text and thus you don't have to figure out which values are text and
which are not.

Regards,
/s


On Feb 12, 7:29 am, Eric Newhuis <> wrote:
> This is where the team puts all the common time-saving programming idioms they find.


More information about the erlang-questions mailing list