[Top][All Lists]

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

Re: GH replacement proposal (includes a bit of Unicode)

From: Dirk Herrmann
Subject: Re: GH replacement proposal (includes a bit of Unicode)
Date: Sat, 15 May 2004 11:50:00 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2) Gecko/20040220

Marius Vollmer wrote:

 Dirk Herrmann <address@hidden> writes:

>> - SCM scm_from_locale_string (unsigned char *str, ssize_t len);
>> Return a new Scheme string initialized with STR, a string encoded
>> according to the current locale. When LEN is -1, STR must be
>> zero-terminated and its length is found that way. Otherwise LEN
>> gives the length of STR.
> I would prefer to have two functions like scm_from_locale_memory
> (with an unsigned len argument) and scm_from_locale_c_string rather
> than using -1 as a magic number. The same holds for the other
> scm_from_<string-type> functions that you describe below.

 Hmm, yes, that might make sense. However, the -1 idiom is pretty
 much standard for this kind of interface, no?

I personally don't like this kind of 'one value, several meanings' paradigm:

- What, if instead of -1, you pass -2? Is it allowed? Is it a run-time error?
 Is it being checked by the routine? At least, the compiler can't help you
 any more.

- Readability suffers. If there is only scm_from_locale_string, there will
 be places in the code like the following:

SCM s = scm_from_locale_string (str, -1); /* not obvious, what the -1 means */

 Compare this with the readability of

   SCM s = scm_from_locale_c_string (str);

 Note that with scm_from_locale_memory there will probably be no
readability problem either, since whoever calls scm_from_locale_memory
must be aware of the length, such that the call will typically look like

SCM s = scm_from_locale_memory (str, len);

with "len" being hopefully some sensible name, thus leading to
self-documenting code.

Best regards,
Dirk Herrmann

reply via email to

[Prev in Thread] Current Thread [Next in Thread]