[erlang-questions] Binary string literal syntax

Sean Hinde sean.hinde@REDACTED
Wed Jun 6 11:41:01 CEST 2018


I had an off list mail with some questions that I’d like to share my answers to

The first question was about my use of the word <<“modern”>>

Modern had a few thoughts behind it:
 - It depends on the greyness of your beard ;)
 - The great re-write of libraries dealing with external string data as input to use binaries instead of strings (especially the json libs)
 - That UTF-8 has emerged as the universal standard for string data

It means that dealing with modern Erlang libs and modern data drives the use of binary strings as the default way of writing strings in Erlang programs where we would once have just used list of int strings

> 
> Anyway, I feel like Erlang is even less of a string-wrangling scripting language than Elixir and so I think I'd find sigils even less helpful.

As a protocol wrangling language I would argue Erlang has no peers, but many more protocols are string based now than when the bit syntax was invented.

> 
> 
>> LFE uses:
>> 
>> #”Some binary string”
> 
> 
> That one's pretty attractive to me. I could see myself writing them that way.

One vote in that direction. Thank you !

> My question, though, is what are the trade-offs of using binaries vs list-of-ints for strings? I think the syntax ought to push people towards the "best" answer. Erlang seems to say list-of-ints and Elixir definitely says binaries.

I think if we had a nicer way to write strings as binaries it would push the needle pretty far in the direction of that as the best answer in a lot more cases.

I don’t see a lot of reasons not to use binary strings as the preferred option - they take less memory, they can be compared, indexed, searched etc much more efficiently than lists as strings

Sean


More information about the erlang-questions mailing list