[erlang-questions] Which is best? string:concat or ++?
Tue May 8 10:40:48 CEST 2012
Here a dumb answer.
"You might not need to concatenate them" - if all you're going to
do is output
the result later then you don't need to concatenate them. For example
X = A ++ B,
X = [A,B], %% <--- this thing is
called an iolist
will result in identical content in the file "foo". In this case
(where you're just going
send the concatenated data to an I/O stream) you don't need to bother
concatenating the data.
If you are building complex iolists (which is very common) and you need
to flatten it, then a good strategy is to build a single iolist (X)
and then call
Using '++' when you don't need to at all is a common programming error :-)
In the cases where you do need it probably both the A and B in A++B should be
small. If A is a long string then you should look for a different algorithm.
On Mon, May 7, 2012 at 3:31 PM, Paul Barry <paul.james.barry@REDACTED> wrote:
> Hi folks.
> This might be a case of a dumb question, but here goes anyway. :-)
> I have two strings, A and B. Is it better to use:
> string:concat(A, B)
> A ++ B
> when combining them to create a new string? I'm writing some code
> that generates a chunk of HTML. I know that using ++ on big lists is
> regarded as a "no-no", but is it acceptable here?
> Paul Barry, w: http://paulbarry.itcarlow.ie - e: paul.barry@REDACTED
> Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.
> erlang-questions mailing list
More information about the erlang-questions