E
Edward Diener
Am I curious about two of the major design decisions for the System::String
class and why they were made. Those two decisions are:
1) System::String is an immutable class, with System::Text::StringBuilder
being the class that allows a string to be modified internally.
2) System::String is a reference class rather than a value class.
OK, I will admit right off, rather than try to forestall my criticism of
these design decisions in some other way, that I am a C++ progammer and that
the std::string class in C++ is mutable and almost always stack-based in
actual use rather than dynamically allocated. Given that prior orientation,
and knowing that the Java string class, like the .NET System::String class,
is also immutable and reference based, I am still curious as to the design
decision in .NET to follow this same path.
The practical reason I mention this is that it seems as if it would have
been much easier from the programmer's point of view to deal with
System::String as a value class and as a mutable class, rather than have to:
1) Make changes to System::String which returns another dynamically
allocated System::String, or using another class,
System::Text::StringBuilder just to make changes, something which seems like
a kludge to me.
2) Create System::Strings simply by writing 'System::String x(...some
constructor)' without having to write 'System::String x = new
System::String(...some constructor)'.
I do realize that any string class which can contain a variable length
series of characters does have to use dynamic memory internally, so that my
criticism of the second design decision above is not base directly on using
dynamic memory rather than stack-based memory. My questioning of the design
decsions above, and being interested in any justifications for them, is
based on ease of use from the programmer's point of view. To me it is much
easier to be able to instantiate a string class directly as a stack-based
object, and change that particular object if necessary, than to have to
instantiate a string as a dynamically allocated object, and have changes
made to that object result in a new string being dynamically allocated and
passed back to me.
class and why they were made. Those two decisions are:
1) System::String is an immutable class, with System::Text::StringBuilder
being the class that allows a string to be modified internally.
2) System::String is a reference class rather than a value class.
OK, I will admit right off, rather than try to forestall my criticism of
these design decisions in some other way, that I am a C++ progammer and that
the std::string class in C++ is mutable and almost always stack-based in
actual use rather than dynamically allocated. Given that prior orientation,
and knowing that the Java string class, like the .NET System::String class,
is also immutable and reference based, I am still curious as to the design
decision in .NET to follow this same path.
The practical reason I mention this is that it seems as if it would have
been much easier from the programmer's point of view to deal with
System::String as a value class and as a mutable class, rather than have to:
1) Make changes to System::String which returns another dynamically
allocated System::String, or using another class,
System::Text::StringBuilder just to make changes, something which seems like
a kludge to me.
2) Create System::Strings simply by writing 'System::String x(...some
constructor)' without having to write 'System::String x = new
System::String(...some constructor)'.
I do realize that any string class which can contain a variable length
series of characters does have to use dynamic memory internally, so that my
criticism of the second design decision above is not base directly on using
dynamic memory rather than stack-based memory. My questioning of the design
decsions above, and being interested in any justifications for them, is
based on ease of use from the programmer's point of view. To me it is much
easier to be able to instantiate a string class directly as a stack-based
object, and change that particular object if necessary, than to have to
instantiate a string as a dynamically allocated object, and have changes
made to that object result in a new string being dynamically allocated and
passed back to me.