[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Namespaces
- From: Ian Mackenzie <ian.e.mackenzie@xxxxxxxxx>
- Date: Thu, 11 Oct 2007 19:06:09 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; bh=49ZPz7IoijbKxRZB4okE3t4bGu6eIMgpgu9TMV/Zzrk=; b=pyVnNPD7ha5Fvkva7s8fvqVhjMrvB4GldQr3zKBFSvFK0dS6qlLGZbijtzUDu/capNJQsCU4CcoIPEVUvFmkb0jS/G8gz2Q8GSu6vRhN0es+AXzBN3LndERhL4i3vrv9Zp7ZPBAZwnQIU92OU44CFzhex3XU0QiBrS8ojyZBP5k=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id; b=cXkXPtrHTK7UYtc33cOI6FJvqiGtTWCdoCCgg6IM9ljS6OyWQFc7leT4Jtk5NDXgBrD8AFCUpixsmP5EpsDEJ80e0350Va0D+u4crfs5gb8CRXavGWsfHitds6F63PqAA3t1Vim7zKjoee8iQfDTo39SoNs3ECXNnwSJdhPEI0U=
Benoît,
Are you sure typedefs aren't supposed to work across namespaces in C++? For
one thing, I've been doing exactly that with Eigen 1 in my code:
typedef long double basic_scalar;
typedef Eigen::Vector<basic_scalar, 3> basic_vector;
and it compiles OK under GCC (Linux and OS X) and MSVC. That might just have
been compilers being lenient, but by looking through 'The C++ Programming
Language' I found an example that did the same sort of thing (section
8.2.8.2, page 182 in my copy):
namespace Lib2 {
// bunch of other examples
typedef Her_lib::String Her_string;
}
Indeed, Stroustrup explicitly mentions that "Usually, I prefer to leave a name
unchanged when including it into a new namespace...However, sometimes a new
name is needed or simply nice to have...There is no specific language
mechanism for renaming. Instead, the general mechanisms for defining new
entities are used."
-Ian
On October 11, 2007 04:23:46 pm Benoît Jacob wrote:
> Thanks for the long e-mail, Donald. I received it as I was reverting to
> namespace Eigen, and so it almost felt good to know that you also were in
> favor of a namespace :)
>
> Anyway, this is committed. I haved added a CCMAIL in the commit message to
> this list, but apparently the mail hasn't yet been sent.
>
> So we currently have everything in a namespace Eigen. And we have a macro,
> USING_EIGEN_DATA_TYPES, that does 'using' on the Matrix class and its
> typedefs (these typedefs are not too polluting thanks to their suffixes,
> like Vector2d).
>
> So many users will be able to do USING_EIGEN_DATA_TYPES, and never have to
> write Eigen::, without polluting the global namespace with names such
> as "Object".
>
> Hope that is satisfying, and thanks Konstantin, Cyrille, Andre, Ben, Donald
> for contributing your opinions,
>
> Benoit
>
> On Thursday 11 October 2007 21:35:08 Donald Ephraim Curtis wrote:
> > Man this is a tough conversation. I do like namespaces, they seem like
> > a proper way to do it because that's why they were put into the
> > language, (although i don't know strousup) but both ways accomplish the
> > same thing, just one is emulating namespaces. If I had to vote I'd say
> > use the namespace Eigen because I like them. I know we did namespaces
> > with Avogadro and I still consider that maybe AMainWindow might have
> > been better, but honestly I don't regret it.
> >
> > I have a couple things for you to consider Benoit then i'll be done. I
> > tried to think this out well and please don't take it as an attack.
> >
> > 1) Using a namespace gives the _option_ to the developer to type out the
> > prefix 'Eigen::' everytime or allow them to do 'using Eigen::Object' or
> > to use 'using namespace Eigen'. If you name the object EiObject you are
> > forcing them to type Ei everytime and even with autocomplete. Having to
> > type Eigen::Object with autocomplete becomes E<tab>::O<tab> whereas
> > EiObject is EiO<tab> so maybe a little typing saved but negligable.
> >
> > 2) The only time you need to worry about the namespace is when declaring
> > a variable or calling a function in that namespace. For the latter you
> > don't want to have global functions prefixed with eiDoSomething (in my
> > opinion). qSort is ackward to me whereas Qt::sort. It could be
> > cosmetic.
> >
> > 3) Namespaces are more proper. Just cause QT doesn't use them doesn't
> > make it right. Qt does use namespaces for their global defines (enums).
> > I find it annoying because I'd just as well do a using namespace Qt when
> > I'm using Qt functions and have it know what enum i'm talking about. I
> > agree that just because they are proper doesn't make them the best way.
> > Consider though that namespaces are a part of a lot of formalisms (XML,
> > Java, Python) and when you look at people wanting to use Eigen for code
> > generated from UML or some higher level formalism like Model Driven
> > Architecture you're going to want that namespace. Also i read an
> > article that when they did bindings for Ruby or something for KDE that
> > they had to use namespaces and had to work around it.
> >
> > 4) There is an argument to be made that even with namespaces that
> > ambiguity can exist. But that's due to bad programming. Just make sure
> > you're not doing something to make up for the problem of a bad
> > programmer. Managing namespaces is a part of being a good programmer.
> >
> > Doesn't KDE now use namespaces? I think it does even though it's a
> > little ugly like KDE:KMainWindow or something like that.
> >
> > Anyways, I think it's up to you. If you like EiVector i'm totally cool
> > with it. You do a termendous job with Eigen and also have contributed
> > to Avogadro so much I think you should do what you want. If anyone is
> > goign to _not_ use your library for that reason then their loss. And if
> > you decide to go Eigen:: and then change your mind i'll help you search
> > and replace with Ei prefix.
> >
> > --
> > Donald
> >
> > Also read the wiki on namespaces maybe that will help ya decide.
> > http://en.wikipedia.org/wiki/Namespace_(computer_science)
> >
> > (Thu, Oct 11, 2007 at 08:55:30PM +0200) Benoît Jacob
>
> <jacob@xxxxxxxxxxxxxxx>:
> > > Argh.
> > >
> > > Seems like aside from me, everybody is either in favor of a namespace,
> > > or doesn't care.
> > >
> > > You, Cyrille, Konstantin, Andre.
> > >
> > > I'm generally in favor of dictatorship, but every dictator has to
> > > listen to the people once in a while.
> > >
> > > So maybe, we'll revert to namespace Eigen:: instead of a prefix.
> > >
> > > But not tonight. Let's give this whole issue more time to ripen.
> > >
> > > Cheers,
> > > Benoit
> > >
> > > On Thursday 11 October 2007 20:48:44 Schleimer, Ben wrote:
> > > > > > Look at what Qt does. Qt classes are not encapsulated in any
> > > > > > namespace, instead they have the Q prefix, like "QObject".
> > > > >
> > > > > Qt was first release at a time when namespaces were not well (if at
> > > > > all) supported by most C++ compiler.
> > > >
> > > > I have to agree with Cyrille. It would be cleaner to use
> > > > Eigen::Object instead of prefixing every class with Ei. Let the
> > > > application programmer figure out which "using" statements they want
> > > > to do. It'll probably be rare to get namespace collisions if eigen is
> > > > the only matrix library used in an application. Plus, when Eigen3
> > > > comes out, it'll be easier for app programmers to which by changing
> > > > the "using EigenX" instead of the prefix.
> > > >
> > > > Cheers
> > > > Ben