A stream is a significantly simpler concept.
Not if the underlying design of the code isn't stream-oriented, it's not.
Adding a stream to code that's not inherently related to a stream is a
complication, not a simplification.
If you have it in your own format internally and want to write that to
some output, this is exactly the time to use a stream.
So what? If you don't, then it's not. Unless you are saying that it's
always the case that you have your own format internally and want to write
that to some output, I don't see how this is at all relevant to the
question at hand.
Are you saying that it's always the case that you have your own format
internally and want to write that to some output?
[...]
Normally you have more information about what those strings represent,
how they're manipulated, etc.
"Normally"? Sorry, but I don't buy that. What's "normal"? In a program
that does a lot of string manipulation, but where the strings are nothing
more than just strings, you don't "have more information about what those
strings represent".
I don't disagree that if you have that information, it's useful to use
it. But I don't see where you think you can assert that all programs have
that information, or that if they don't that the program is thus
necessarily "very wrong".
Use the right tool for the job. Sometimes StringBuilder isn't the right
tool. But sometimes it is.
I've seen plenty of StringBuilder usage to construct the message for an
exception. Perhaps I'm optimistic, but I'd rather programmers were
competent, or at least willing to read the "complete discussion".
I've never seen a statement from a reliable source (i.e. one of the
regulars here who generally post on the topic) that suggests that using a
StringBuilder for concatenating a fixed number of strings would be
desirable. There's never been a discussion like this that should have led
to someone using StringBuilder to construct a message for an exception
(except, of course, in situations where that message includes a large
number of strings retrieved from some source and concatenated inside a
loop...I'd say that'd be a good example of how not to construct a message
for an exception, but it's certainly a good place to use a StringBuilder).
Because programming is about the details. Bugs occur when a programmer
fails to consider the details, and instead chooses to only look at the
"basic point".
You are misinterpreting the basic point. See my previous paragraph. I've
never seen the "basic point" presented in a way that should lead to the
things you describe.
Erm... this is me trying to construct a scenario where a StringBuilder
is a good idea.
I don't think it's necessary to invoke "code that should have got the
author many years in jail" in order to justify the use of the
StringBuilder class. Doing so only further implies that using the
StringBuilder is a bad thing. I realize that does align with your goal
here, but it's circular logic. You can't legitimately use a contrived
scenario that carries the implication that using the StringBuilder is a
bad thing as some sort of proof that using the StringBuilder is a bad
thing.
If you're going to come up with an example where a StringBuilder is a good
idea, come up with one that's part of normal, well-designed,
well-implemented code. Of course, if you do that, your point falls
apart. But the fact that you can come up with examples of bad code where
StringBuilder is useful doesn't really relate to this discussion. I'm not
talking about StringBuilder only being useful in bad code.
[...]
Given only the information you mention with respect to profiling, how
can you even assert that a rewrite would be beneficial, never mind
necessary? It's entirely possible that changing the code to use a
StringBuilder is not only a quick change, but a perfectly appropriate
one (i.e. not "dirty" at all).
I'd consider refactoring code and leaving the huge WTF in the middle of
it to be "dirty". Sometimes it's commercially necessary, but it's not
nice.
Who said anything about "leaving the huge WTF in the middle of it"? All
you asserted was that profiling found the code is bounded by the speed it
can concatenate strings.
I think you need to re-read exactly what I wrote.
Where? Did you not write "I will admit they [good reasons to use a
StringBuilder] do exist?" I don't see how you can write that, and yet at
the same time assert that any program that uses StringBuilder is de facto
"very wrong".
Pete