On Wed, 28 Dec 2011 14:06:06 +0200, Peter Alexander
<[email protected]> wrote:
string is immutable(char)[]
I rarely *ever* need an immutable string. What I usually need is
const(char)[]. I'd say 99%+ of the time I need only a const string.
This is quite irritating because "string" is the most convenient and
intuitive thing to type. I often get into situations where I've written
a function that takes a string, and then I can't call it because all I
have is a char[]. I could copy the char[] into a new string, but that's
expensive, and I'd rather I could just call the function.
I think it's telling that most Phobos functions use 'const(char)[]' or
'in char[]' instead of 'string' for their arguments. The ones that use
'string' are usually using it unnecessarily and should be fixed to use
const(char)[].
In an ideal world I'd much prefer if string was an alias for
const(char)[], but string literals were immutable(char)[]. It would
require a little more effort when dealing with concurrency, but that's a
price I would be willing to pay to make the string alias useful in
function parameters.
As you said string is not a structure but an alias.
Your arguments not against string but the functions that support only
strings which you think they shouldn't.
If you are sure, that function is able to work on your "string" (but it
won't) it just shows that we need to focus on the function rather than the
string, no?