[Haskell-cafe] Reversing a string of words: C# v Perl V Ruby v
Haskell
Andrew Savige
ajsavige at yahoo.com.au
Sun Dec 10 15:30:34 EST 2006
--- Neil Mitchell <ndmitchell at gmail.com> wrote:
> Why not: String.Join(" ", words) ?
>
> Saves all the hassle with StringBuilder etc.
I agree. The StringBuilder code could be replaced with:
Array.Reverse(words);
return String.Join(" ", words);
However, every response to this question I've seen (admittedly only three
or four so far) used StringBuilder. When I ask, "why not use Join?" most
C# programmers seem to respond that StringBuilder is "faster" (I haven't
measured the difference in performance).
To be fair to C#, I'm not a C# expert and haven't asked this question
(yet;-) in a public C# forum but StringBuilder seems the "natural"
approach of practising C# programmers.
Perhaps most practicing Java programmers would similarly reach straight
for the StringBuffer hammer? It would be interesting to pose this problem
to a Java expert (which is not me). Given their similarities, I would
expect a Java and C# solution to this problem to look fairly similar.
Cheers,
/-\
Send instant messages to your online friends http://au.messenger.yahoo.com
More information about the Haskell-Cafe
mailing list