E
Edward Diener
While most of the design of the string class is not too bad, the one member
function which really sticks out as being incorrectly designed is the
Replace member function. After an Insert member function which quite
reasonably inserts another string starting at a specific location and a
Remove function which removes a number of characters from the string
starting at a specific location, I would have assumed, without having looked
first, that a Replace function would replace a number of characters of a
string starting at a specific location with another string. Instead what we
get for the Replace function has nothing to do with that, but is a function
whose name would have best been ReplaceAllInstances, and which replaces all
instances within the string of either a character with another character or
a substring with another substring.
While a ReplaceAllInstances is certainly a useful and worthy function (
along with a RemoveAllInstances which is not provided in the string class ),
and while a normal Replace, as I have described it, can be done with a
Remove followed by an Insert, I think that the designer(s) of the string
class really fell asleep by not providing a Replace function which acts as I
have described and which would be the orthogonal equivalent of the design of
the Remove and Insert functions. As it is, the string Replace function is
misnamed and has nothing to do with the meaning of a normal string Replace.
Was everyone at MS asleep the day this anomaly was created, or was the
designer of this member function just too proud to create a Replace function
which would have the functionality which one expects in a well-designed
string class ? ( rhetorical question )
This anomaly just goes to show that even at a company with the reputation of
technical excellence as MS, people sometimes simply don't know how to design
classes and components correctly.
function which really sticks out as being incorrectly designed is the
Replace member function. After an Insert member function which quite
reasonably inserts another string starting at a specific location and a
Remove function which removes a number of characters from the string
starting at a specific location, I would have assumed, without having looked
first, that a Replace function would replace a number of characters of a
string starting at a specific location with another string. Instead what we
get for the Replace function has nothing to do with that, but is a function
whose name would have best been ReplaceAllInstances, and which replaces all
instances within the string of either a character with another character or
a substring with another substring.
While a ReplaceAllInstances is certainly a useful and worthy function (
along with a RemoveAllInstances which is not provided in the string class ),
and while a normal Replace, as I have described it, can be done with a
Remove followed by an Insert, I think that the designer(s) of the string
class really fell asleep by not providing a Replace function which acts as I
have described and which would be the orthogonal equivalent of the design of
the Remove and Insert functions. As it is, the string Replace function is
misnamed and has nothing to do with the meaning of a normal string Replace.
Was everyone at MS asleep the day this anomaly was created, or was the
designer of this member function just too proud to create a Replace function
which would have the functionality which one expects in a well-designed
string class ? ( rhetorical question )
This anomaly just goes to show that even at a company with the reputation of
technical excellence as MS, people sometimes simply don't know how to design
classes and components correctly.