473,497 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Right" use of namespaces

Hi,
I am currently trying to group my classes using namespaces. But since
these groups are not really independend I end up to have a lot of
forward declarations.

My first approache was to enclose all class definitions and forward
declarations in the corresponding headers directly. Which turned out to
make it difficult to read the header, and created a lot of overhead.

Therefore at the moment I am using a headerfile dedicated to forward
delcarations which are enclosed in the correct namespace. Is this a
common strategie? What are the up- and downsides from your perspective?
What are the alternatives?

In the headerfiles I am not using the "using-directive" to import
classnames in the namespace, because I don't want to make them
accessible through a second namespace. Same reason we I don't create a
"shortcut-namespace" (e.g. namespace abc = ada::basic::cobol). But
since I am using the namespace hierachie directly, first there is a lot
of overhead in writting and second if I change the namespaces I have to
change it in every single file. Is there an alterative? If the
using-directive would make the namespace/class imported visible from
outside it would be my perfect choice.

In the .cpp files I take advantage of the the using-directive a lot.
Since all .cpp-files are closed entities it should be fine to do so,
right?

Thanks for your help,
Thomas Kowalski

Aug 14 '06 #1
4 1892
In article <11**********************@b28g2000cwb.googlegroups .com>,
"lionheart" <th***@gmx.dewrote:
Hi,
I am currently trying to group my classes using namespaces. But since
these groups are not really independend I end up to have a lot of
forward declarations.

My first approache was to enclose all class definitions and forward
declarations in the corresponding headers directly. Which turned out to
make it difficult to read the header, and created a lot of overhead.

Therefore at the moment I am using a headerfile dedicated to forward
delcarations which are enclosed in the correct namespace. Is this a
common strategie? What are the up- and downsides from your perspective?
What are the alternatives?

In the headerfiles I am not using the "using-directive" to import
classnames in the namespace, because I don't want to make them
accessible through a second namespace. Same reason we I don't create a
"shortcut-namespace" (e.g. namespace abc = ada::basic::cobol). But
since I am using the namespace hierachie directly, first there is a lot
of overhead in writting and second if I change the namespaces I have to
change it in every single file. Is there an alterative? If the
using-directive would make the namespace/class imported visible from
outside it would be my perfect choice.

In the .cpp files I take advantage of the the using-directive a lot.
Since all .cpp-files are closed entities it should be fine to do so,
right?
Yes. However I think what you are doing with namespaces is inappropriate
to begin with.

The namespace mechanism exists to avoid name collisions when different
libraries are used in the same program. They also come in handy when
multiple people are working in the same program to avoid name
collisions. An individual working alone simply shouldn't have the kinds
of problems that namespaces are meant to solve. All IMHO of course.
Aug 14 '06 #2
An individual working alone simply shouldn't have the kinds
of problems that namespaces are meant to solve. All IMHO of course.
Well, since c++ don't have packages I think namespaces is what comes
most close to it. Therefore I use it to clarify the concepts of my
software by grouping classes. I think more then 8-12 classes at the
same level of hierarchie are too troublesome to understand.

Thanks for your answer,
Thomas Kowalski

Aug 14 '06 #3

Daniel T. wrote:
In article <11**********************@b28g2000cwb.googlegroups .com>,
Yes. However I think what you are doing with namespaces is inappropriate
to begin with.

The namespace mechanism exists to avoid name collisions when different
libraries are used in the same program. They also come in handy when
multiple people are working in the same program to avoid name
collisions. An individual working alone simply shouldn't have the kinds
of problems that namespaces are meant to solve. All IMHO of course.
I agree, except that an individual might have the kind of problems
namespaces are meant to solve if they are both the application
developer and the library author. I keep all of the general tools and
utilities I create in their own namespace. Then I know I can reuse them
as a useful library without the future fear of name clashes. More often
than not it, ends up being perfectly safe to include the whole
namespace with a using directive, but the option of namespace
protection is there for the time I need it.

Gavin Deane

Aug 14 '06 #4
In article <11*********************@i3g2000cwc.googlegroups.c om>,
"lionheart" <th***@gmx.dewrote:
An individual working alone simply shouldn't have the kinds
of problems that namespaces are meant to solve. All IMHO of course.

Well, since c++ don't have packages I think namespaces is what comes
most close to it. Therefore I use it to clarify the concepts of my
software by grouping classes. I think more then 8-12 classes at the
same level of hierarchie are too troublesome to understand.
Maybe I'm showing my old school roots, but I use the header and source
files for that sort of thing.
Aug 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1618
by: Evgeny Gopengauz | last post by:
What is the way recommended by Microsoft for distributing the MSSQL database with end-user application if I don't like to use sql-scripts because I need to hide the stored procedures sources (they...
1
1417
by: Edward King | last post by:
I have a statement in a asp,like follows£º var str=window.top.main.document.all.contenttext.value; I use IIS5.0 to deploy this asp,then I visit this asp like follows:...
6
12978
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
44
9382
by: Viken Karaguesian | last post by:
Hello all, On occasion I want to open hyperlinks (images, etc.) in a new window. In the past, I've used target="_blank" to open the link in a new window. However, using the "target" attribute...
1
8010
by: tshad | last post by:
I have columns with text and radio buttons that I would like to center or put to the right of the cell, but the attribute ItemStyle-HorizontalAlign="right" doesn't seem to work. ...
7
10835
by: the_grove_man | last post by:
How do I invoke a "Right-Click" Programmtically? John
3
8729
by: mehdi | last post by:
I have a field that is a memo and I have a report displaying the text in that memo. What I need to know is how to "justify" the text right to left. The reason is in arabic and persian...
8
4595
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this "3145728". But the MouseButtons Enum contains only Left,...
2
1717
by: Tom P. | last post by:
I am writting a extended ListView control and I'd like to stop the default behavior when a user right-clciks on a non-label area and then drags causing a "marching ants" selection box to appear....
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.