Strokes framework naming problem
Silvio Heinrich
plassy at web.de
Tue Jul 12 12:57:52 CEST 2011
On 07/11/2011 10:51 AM, Boudewijn Rempt wrote:
> Namespaces aren't any different from prefixes -- except that because you can declare a namespace used, the prefix isn't used everywhere. And I find that confusing. I prefer to see StrokeJobStrategyFreehand everywhere, instead of sometimes StrokeJobStrategy::Freehand and sometimes just Freehand.
>
>
Ok, thats a point but namespaces are like every other c++ feature it has
to be used the right way.
the "using namespace" statement should normally be avoided (but of
course there are exceptions for that).
And without namespaces people tent to avoid a consistent naming of
classes because the names would simply get too long.
For example in krita/image/commands we have this classes:
class KisImageLayerRemoveCommand;
class KisImageSetProjectionColorSpaceCommand;
class KisDeselectGlobalSelectionCommand;
class KisReselectGlobalSelectionCommand;
It seems to me that the right prefix for all classes would have been
KisImage.
And I find it understandable if people want to avoid such long names.
KisImageSetProjectionColorSpaceCommand::KisImageSetProjectionColorSpaceCommand(KisImageWSP
image, const KoColorSpace * afterColorSpace)
: KisImageCommand(i18nc("(qtundo-format)", "Convert Image Type"),
image)
{
m_beforeColorSpace = image->colorSpace();
m_afterColorSpace = afterColorSpace;
}
with namespaces:
using namespace Kis;
using namespace Kis::Image::Command;
SetProjectionColorSpace::SetProjectionColorSpace(ImageWSP image, const
KoColorSpace * afterColorSpace)
: Command(i18nc("(qtundo-format)", "Convert Image Type"), image)
{
m_beforeColorSpace = image->colorSpace();
m_afterColorSpace = afterColorSpace;
}
or something like this:
void KisSomeClass::someMethod()
{
do something...
if(test something) {
whatever.addCommand(new
KisImageSetProjectionColorSpaceCommand(m_image, m_colorSpace));
whatever.addCommand(new KisImageLayerRemoveCommand(m_image,
m_colorSpace));
...
}
...
}
With namespaces:
using namespace Kis;
void SomeClass::someMethod()
{
using Image::Command::SetProjectionColorSpace;
using Image::Command::RemoveLayer;
do something...
if(test something) {
whatever.addCommand(new SetProjectionColorSpace(m_image,
m_colorSpace));
whatever.addCommand(new RemoveLayer(m_image, m_colorSpace));
...
}
...
}
Of course both versions work and I've could have used typedefs as well but
I just think that the name of a class should tell what the class does
and not
what it's location in the source tree is.
It's imho more readable with the locational information separated from
the logic.
Maybe it's anyway to late to put everything in namespaces since it had
to be considered from the start...
More information about the kimageshop
mailing list