On Mar 23, 4:13 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Thu, 19 Mar 2009 15:42:30 -0700 (PDT), James Kanze
> <james.ka...@gmail.com> wrote:
> > On Mar 19, 9:37 pm, Giuliano Bertoletti <gbe32...@libero.it> wrote:
> >> peter koch ha scritto:
> >> > What is your problem with using free functions instead -
> >> > e.g. void tolower(std::string& string) or std::string
> >> > substring(std:string const& s, int begin, int end)?
> >> It tends to make the code less readable.
> > That depends.
> You could argue that free functions are more readable because
> readers familiar with std::string know that the object itself
> represents and can do. All they need to learn is what
> tolower() and substring() do, and they can use them directly
> in their std::string-based code.
One could. More generally, I don't think that there's a
fundamental difference in readability between the two syntaxes,
"a.f()" and "f( a )". Any difference is cultural or due to
habits. On the other hand, mixing the two, i.e. having, say
"a.tolower()" but "toupper( a )", would certainly doesn't help
readability. On the third hand, there are different "levels"; I
don't see any real problem with s.replace() but toupper( s ),
for example: functions which manipulate the underlying bytes,
without consideration of the encoding, are members; functions
which consider the semantics of those bytes, as characters, are
free functions.
One could also argue for a Text class, using std::string in its
implementation, but also containing information concerning the
encoding and the locale. This could lead to some interesting
questions: concatenating a Text with ISO 8859-1 encoding and one
with ISO 8859-5 encoding might result in a Text with UTF-8
encoding, but what happens when you concatenate a Text in French
locale with one in Swedish or Turkish. (In French, ä collates
with a, and the upper case of i is I. In Swedish, ä collates
immediately after z, and in Turkish, the upper case of i is
\u0130.)
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|