KDE/kdelibs
Ralf Habacker
ralf.habacker at freenet.de
Sat Oct 15 08:22:43 CEST 2005
Am Dienstag, 11. Oktober 2005 23:28 schrieb Jarosław Staniek:
> Ralf Habacker said the following, On 2005-10-11 23:15:
> > Am Dienstag, 11. Oktober 2005 22:50 schrieb Jarosław Staniek:
> >>Ralf Habacker said the following, On 2005-10-11 20:51:
> >> > Am Dienstag, 11. Oktober 2005 18:37 schrieb Jarosław Staniek:
> >> >>David Faure said the following, On 2005-10-11 18:30:
> >> >>>On Tuesday 11 October 2005 18:27, Jaroslaw Staniek wrote:
> >> >>>>+2005-10-11
> >> >>>>+ It's good idea to append always a space to string definitions:
> >> >>>>+ obj.libs = ' lib1 lib2 ' instead of 'lib1 lib2' because then
> >> >>>>+ adding
> >> >>>>+
> >> >>>>+ obj.libs += 'lib3'
> >> >>>>+
> >> >>>>+ will cause horrible error: 'lib1 lib2lib3'
> >> >>>>+ ^^
> >> >>>>+
After thinking a while about this stuff, what about to prefix a ' ' instead of
appending until the overload stuff is ready, which seems to me more nature.
When I'm working with strings I always take care about delimiters in the
appended string like this
strcpy(dest,"a")
strcat(dest, " b")
instead of
strcpy(dest,"a ")
strcat(dest, "b")
> >> >>>Isn't that the whole reason for using the [] notation ("list"?), so
> >> >>> that it's possible to append without whitespace problem?
> >> >>
> >> >>Heh, of course. But people still like to use 'lib1 lib2' instead of
> >> >>['lib1', 'lib2']. What to do to solve this? Hmm, maybe to overload "="
> >> >>operator so that only lists are allowed?
> >> >
> >> > Is that possible with python ?
> >>
> >>Yes, except overloading assignment operator is possible because python
> >>handles variables as references.
> >>
> >>See attached code of StringList class and example use. The class' name
> >>should be better selected...
> >>
> >>It may work unless somebody just enters:
> >>
> >>obj = env.kdeobj('shlib', env)
> >>obj.libs = 'libname'
> >> ^^
> >>
> >>To avoid the risk we need to:
> >>1. init check type of the obj.libs to StringList() in kdeobj
> >>2. on obj.execute() we need to check if type(libs) == StringList
> >> --- obvious error message is better than wrong behaviour...
> >
> > I've tried an example on
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/389916
> >
> > but unfortunally my python knowledge is more general and I had no success
> > to apply this.
>
> Hmm, do you mean following use case?
>
> obj = env.kdeobj('shlib', env)
> obj['libs'] = 'libname'
>
> instead of
> obj.libs = 'libname'
>
>
> If this is good enough, hmm.. OK to me.
>
> David?
More information about the Kde-buildsystem
mailing list