Re: how to submit a feature request for glib? oversight?



begin: Eric M. Monsler <emonsler beamreachnetworks com> quote
Peter Jay Salzman <p dirac org> writes:
(snip)
is there a reason i'm not thinking of why they don't do this? 
 
hi eric,

thanks for the thoughtful reply.

Even if the API were being created from scratch, I think that a very
good argument could be made that the length should not be returned,
because doing so would encourage developers to keep track of the string
length separately.  
 
i'm not sure i agree with "very good".  i'm not sure it would encourage such
a thing, simply because the length is always obtainable by:

        mystring->len

if every single solitary function in glib returned the length of the string,
i can't see it encouraging keeping track of lengths because mystring->len is
there.   we're assuming the programmer has intelligence.  if not, he/she gets
what he/she deserves!   :)


There is already a public field specifying the length.  That should be
accessed when the length is required.  Doing so prevents a whole class
of possible errors in which the length might be stored, and then later
used incorrectly after another manipulation of the GString.  

Furthermore, given that a major feature of using GStrings is that the
developer (and application) rarely needs to care low long the string is
when doing operations on it, returning the length all of the time would
clutter the code considerably.

absolutely true.  but i'm not talking about returning the length of a string.
not at all!  i'm talking about returning the number of characters written to
a string.  very different indeed!   this information isn't as readily
available.  you have to:

1. store GString mystring->len somewhere
2. get strlen(char *)
3. subtract

it would be much easier to simply return the number of characters written.

anyway, it was just a thought.  it would also be more elegant for the glib
functions to mimic the corresponding glibc functions.  although i'm not
usually after elegance (i'm not that good of a programmer; i'm just someone
who enjoys programming more than he should).  i'm after functionality.  :)

i can see your point for the snprintf type functions (which do return a
GString, i think).  but the append and append_c functions (imho) would
certainly be more useful returning SOMETHING.  what i'm saying is that the
"something" should be the number of characters they write to the target
GString.   :)

pete

-- 
"The following addresses had permanent fatal errors..."      p dirac org
                               -- Mailer Daemon              www.dirac.org/p




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]