[bt-devel] namespace problems

David White bt-devel@crosswire.org
Tue, 22 Oct 2002 07:57:20 +1000


----- Original Message -----
From: "Nikolay Igotti" <Nikolay.Igotti@Sun.Com>
To: <bt-devel@crosswire.org>
Sent: Tuesday, October 22, 2002 3:34 AM
Subject: Re: [bt-devel] namespace problems


> On 21 Oct 2002, David White wrote:
>
> > On Mon, 2002-10-21 at 07:49, Nikolay Igotti wrote:
> > >  Sure, something like this:
> > > const QString& ResourseManager::getToolTip(QString& key) and call it
like
> > > this:
> > > ResourseManager::getToolTip("mainMenu::file::quit")
> >
> > yes, this seems reasonable. Although, you could just have an extern
> > global std::map to do the job...
> >
> > std::map<QString,QString> tooltips;
>  Above approach would help if you want to change implementation to do
> something fancy (like load resourses on demand or provide missed
> resourses).

Well you can change the implementation with my approach too. Just provide an
object which overloads operator[] in place of tooltips, and do whatever fun
stuff you want in there. Not that the difference between approaches is a big
deal.

>
> >
> > >
> > >  BT is very C++ heavyweight (templates, STL) and add yet another C++
> > > feature where it's not needed isn't a good idea.
> >
> > BibleTime is written in C++. What's wrong with it using the features of
> > the language it's written in? Namespaces or namespace-like features are
> > common in almost all modern programming languages (Perl, Python, C#,
> > Java, to name a few), and I don't see any problem using them. Even Sword
> > has gone toward using namespaces recently.
>  Well, to be honest I don't think C++ is "language", maybe features
> bloated meta-language.

I think this may have been true once, but not anymore: C++ is an ISO/ANSI
standardized language these days, and as long as you compile on reasonably
modern compilers, and don't use esoteric or truly advanced language
functionality (partial specialization of templates and so forth) you aren't
going to have too many problems.

> My own preference is to code on some subset of C++
> which I'm sure is portable (something like Mozilla people describe in
> their portability guidelines),

I think Mozilla is basically written in C. It might as well be for how few
C++ features they use. They might as well just get the extra platform
support, and program in straight C, imho.

> and which doesn't use:
>  - exceptions

Exceptions may have once been considered 'advanced', but I don't think they
are or should be, anymore. Certainly, in my experience, writing robust
non-trivial programs in C++ without exceptions is painful. I have had alot
of experience taking code that used error codes and converting it to
exceptions, and resulting in code that is 33-50% as long.

>  - templates (well, beside STL) or some very rare cases when they're
>    really needed

I wouldn't use templates for any of the kinda stuff that people like Andrei
Alexandrescu use them for, however I don't see a problem for any
container-of-type-T type functionality, for callbacks, and so forth.

>  - namespaces (gcc had prioblems with them some time ago)

But, it doesn't anymore.

Basically, these are only concerns if you are targetting compilers which are
now outdated. Mozilla does try to do this. If BibleTime wanted to do this,
much more work would have to be done on maintaining portable code than is
done currently anyhow (as far as I can see; I'm not an active BibleTime
developer). I really don't see the problem with targetting major compilers:
gcc, MSVC++, and perhaps a couple of others.

-David.

>
> >
> > For truly advanced C++ features, which do not have good platform
> > support, such as partial specialization of templates, I can understand
> > not using them. Namespaces are a fairly basic feature.
>  You're right, but in this case I think we could live without use of this
> feature.
>
>  Nikolay
>
>
> > > >
> > > > >  Joachim, are you sure this namespace based approach is good way
to do
> > > > > i18n and resources management? I feel it's not. Maybe resourse
file
> > > > > +resouse manager would be better?
> > > > >
> > > > >  Nikolay.
> > > > >
> > > > > On Sat, 19 Oct 2002, Joachim Ansorg wrote:
> > > > > > David White, I think this eMail is especially for you because
you know
> > > > > > the namespaces well.
> > > > > >
> > > > > > You pointed me into the direction to use namespaces for the
treelike
> > > > > > structure I wanted.
> > > > > >
> > > > > > Now I have something like
> > > > > >
> > > > > > namespace CResMgr {
> > > > > >   inline const QString makeToolTip( const QString& text ) {
> > > > > >     return text;
> > > > > >   };
> > > > > >   inline const QString makeWhatsThis( const QString& title,
const
> > > > > > QString& description )  {
> > > > > >     return
> > > > > >
QString::fromLatin1("<center><B>%1</B></center><HR>%2").arg(title).arg(de
> > > > > >scription); };
> > > > > >
> > > > > >   namespace mainMenu { //Main menu
> > > > > >     namespace file { //Main menu->File
> > > > > >       namespace clearQueue {
> > > > > >         const QString tooltip     = makeToolTip( i18n("Clear the
printing
> > > > > > queue") );
> > > > > >         const QString whatsthis   = makeWhatsThis( tooltip,
i18n("Clear
> > > > > > the print queue of BibleTime. All items will be removed from the
list and
> > > > > > the print button will be disabled.") );
> > > > > >         const QString icon        =
QString::fromLatin1("queue");
> > > > > >         const KShortcut accel     = KShortcut();
> > > > > >         const char* actionName    = "fileClearQueue_action";
> > > > > >       }
> > > > > >       namespace print { //a standard action
> > > > > >         const QString tooltip     = makeToolTip( i18n("Open the
> > > > > > printerdialog") );
> > > > > >         const QString whatsthis   = makeWhatsThis( tooltip,
i18n("Open
> > > > > > the printer dialog of BibleTime.  Here you can edit the print
queue and
> > > > > > assign styles to the items.") );
> > > > > >       }
> > > > > >       namespace quit { //a standard action
> > > > > >         const QString tooltip     = makeToolTip( i18n("Close
BibleTime")
> > > > > > ); const QString whatsthis   = makeWhatsThis( tooltip,
i18n("Close
> > > > > > BibleTime and save the settings.") );
> > > > > >       }
> > > > > >     }
> > > > > > }
> > > > > > etc.
> > > > > >
> > > > > > But compiling BibleTime with this header included in two or more
places I
> > > > > > get the following compiler warnings about multiple symbol
definitions:
> > > > > >
> > > > > >
./frontend/searchdialog/libsearchdialog.a(csearchdialog.o)(.data+0x0):
> > > > > > multiple definition of
`CResMgr::mainMenu::file::clearQueue::actionName'
> > > > > > bibletime_init.o(.data+0x0): first defined here
> > > > > >
./frontend/searchdialog/libsearchdialog.a(csearchdialog.o)(.data+0x4):
> > > > > > multiple definition of
> > > > > > `CResMgr::mainMenu::view::showMainIndex::actionName'
> > > > > > bibletime_init.o(.data+0x4): first defined here
> > > > > >
./frontend/searchdialog/libsearchdialog.a(csearchdialog.o)(.data+0x8):
> > > > > > multiple definition of
`CResMgr::mainMenu::mainIndex::search::actionName'
> > > > > > bibletime_init.o(.data+0x8): first defined here
> > > > > >
./frontend/searchdialog/libsearchdialog.a(csearchdialog.o)(.data+0xc):
> > > > > > multiple definition of
> > > > > > `CResMgr::mainMenu::window::loadProfile::actionName'
> > > > > > bibletime_init.o(.data+0xc): first defined here
> > > > > >
> > > > > > How can I avoid these problems? I have no idea.
> > > > > > Thank you very much for any help!
> > > >
> > > >
> > >
> >
> >
> >
>
>