473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Organizing source in namespaces.

I've come to the decision to use multiple namespaces for a very
specific reason:

I like to use descriptive names of UDTs and I sometimes come up with
long UDT names (and file names too, since I name a source file after
the UDT that is defined in it, if any).

I've also noticed, however, that certain types are related more than
logically but also lexically - they start with the same word (which
happens to be the basic concept that they relate to). So, these UDTs
can be grouped together into a namespace. Thus the leading word would
drop out and become the name of the namespace. This would shorten both
names of UDTs and names and source files.

There is a little caveat, however - when I drop the leading word out I
may come up with conflicting file names. Here's why: in spite of
relating to different basic concepts the UDTs defined in those files
have other, less important, concepts in common, which, or course, come
after the name of the first concept in the name of the UDT(and source
file).

There is, of course, at least two ways out of this situation:
1) give up descriptive names; I wouldn't do that for the time being -
I'm used to them and I find them convenient; besides, if names of UDTs
get really long, I tend to shorten them to acronyms (capital first
letters of each word) despite my desire to avoid acronyms in source
code;
2) put each namespace into a separate folder; this will avoid file name
conflicts and since names of UDTs will become shorter I can get some
acronyms back to their full form;

Option 2 seems to be the best one for now. Could anyone else share some
experience or give ideas about my problem?

Aug 11 '05 #1
6 1615
BigMan wrote:
I've come to the decision to use multiple namespaces for a very
specific reason:

I like to use descriptive names of UDTs and I sometimes come up with
long UDT names (and file names too, since I name a source file after
the UDT that is defined in it, if any).

I've also noticed, however, that certain types are related more than
logically but also lexically - they start with the same word (which
happens to be the basic concept that they relate to). So, these UDTs
can be grouped together into a namespace. Thus the leading word would
drop out and become the name of the namespace. This would shorten both
names of UDTs and names and source files.

There is a little caveat, however - when I drop the leading word out I
may come up with conflicting file names. Here's why: in spite of
relating to different basic concepts the UDTs defined in those files
have other, less important, concepts in common, which, or course, come
after the name of the first concept in the name of the UDT(and source
file).

There is, of course, at least two ways out of this situation:
1) give up descriptive names; I wouldn't do that for the time being -
I'm used to them and I find them convenient; besides, if names of UDTs
get really long, I tend to shorten them to acronyms (capital first
letters of each word) despite my desire to avoid acronyms in source
code;
2) put each namespace into a separate folder; this will avoid file name
conflicts and since names of UDTs will become shorter I can get some
acronyms back to their full form;

Option 2 seems to be the best one for now. Could anyone else share some
experience or give ideas about my problem?


I think we all went through different phases while we learn
programming. First your programs have no structure whatsoever and you
don't understand why it should have one (it works, so..). Then you
have an incredible need of structure, you classes are named
computer::Equipment::Memory::Flash, defined in the file
~/dev/c++/projects/starting/car/src/computer/equipment/memory/flash/class_def.h.

And then you realize it doesn't really matter, as long as what you do
is consistent and practical. Are you consistent? Is your code
practical? Probably not. Try to minimize the complexity of your naming
scheme, C++ can be complex enough by itself.
Jonathan

Aug 11 '05 #2
I must confess that you really have a point here - the code should be
consistent and practical. But organization is a prerequisite for this.
Let me illustrate this with the help of a simple example
At present one of my projects consists of 150+ files and it gets more
and more difficult for me to manage them and find manually what I need
(the IDE has hard time doing so, too). So what am I supposed to do?
Leave all those files in the same folder and in the same namespace? I
do not think this is very practical, since I tend to lose more and more
time getting my way round.

Aug 11 '05 #3
UDT = user defined type
Sorry for having forgotten to mention this!

Aug 11 '05 #4
BigMan wrote:
I must confess that you really have a point here - the code should be
consistent and practical. But organization is a prerequisite for this.
Let me illustrate this with the help of a simple example
At present one of my projects consists of 150+ files and it gets more
and more difficult for me to manage them and find manually what I need
(the IDE has hard time doing so, too). So what am I supposed to do?
Leave all those files in the same folder and in the same namespace? I
do not think this is very practical, since I tend to lose more and more
time getting my way round.


Very general answers (you may add a "most of the times" or "unless you
have a good reason" to each):

1) Quote the message you are answering to (that one is final)
2) Minimize the number of files. Don't use one header/implementation
for each class (a la Java). Group them in a more general fashion.
3) Don't nest namespaces.
4) Use short but descriptive names (acronyms may be ok)
5) Use free functions, declared in the header it relates to, instead of
member functions when you can. It greatly simplifies the naming. Don't
replace Car::start() by car_start(Car&); replace it by start(Car&) and
put it in the header. Most of the times, namespaces, headers and
overloading will prevent name clashes.
6) Change the IDE :)
Jonathan

Aug 12 '05 #5
Jonathan Mcdougall wrote:
BigMan wrote:
I must confess that you really have a point here - the code should be
consistent and practical. But organization is a prerequisite for this.
Let me illustrate this with the help of a simple example
At present one of my projects consists of 150+ files and it gets more
and more difficult for me to manage them and find manually what I need
(the IDE has hard time doing so, too). So what am I supposed to do?
Leave all those files in the same folder and in the same namespace? I
do not think this is very practical, since I tend to lose more and more
time getting my way round.

Very general answers (you may add a "most of the times" or "unless you
have a good reason" to each):

1) Quote the message you are answering to (that one is final)
2) Minimize the number of files. Don't use one header/implementation
for each class (a la Java). Group them in a more general fashion.
3) Don't nest namespaces.
4) Use short but descriptive names (acronyms may be ok)
5) Use free functions, declared in the header it relates to, instead of
member functions when you can. It greatly simplifies the naming. Don't
replace Car::start() by car_start(Car&); replace it by start(Car&) and
put it in the header. Most of the times, namespaces, headers and
overloading will prevent name clashes.
6) Change the IDE :)
Jonathan


Hi,

I don't get point 5. Why would you use free functions instead of class
methods? I don't see why it simplifies naming.

Using start( myCar ) instead of myCar.start() seems a bit C-ish to me.
I do see however that in C you probably need to use car_start() since
you also might have a plane_start() or something, and in C++ they can
both be called start(). But still I could do myCar.start() or
myPlane.start().

But please tell me what I'm missing or when this construct is preferred,
cause I'm certainly not too old to learn.

Mark
Aug 18 '05 #6

Capstar wrote:
Jonathan Mcdougall wrote:

5) Use free functions, declared in the header it relates to, instead of
member functions when you can. It greatly simplifies the naming. Don't
replace Car::start() by car_start(Car&); replace it by start(Car&) and
put it in the header. Most of the times, namespaces, headers and
overloading will prevent name clashes.
6) Change the IDE :)
I don't get point 5. Why would you use free functions instead of class
methods? I don't see why it simplifies naming.


Because these function are not called Car::start() anymore, only
start(). Particularily, using pointer to functions is quite simpler
than member function pointers (from a my-names-are-too-long pov, of
course).
Using start( myCar ) instead of myCar.start() seems a bit C-ish to me.
Well I've taken the habit (like many) to only make a function a member
if it needs access to its internal representation. It certainly don't
look C-ish to me.
But please tell me what I'm missing or when this construct is preferred,
cause I'm certainly not too old to learn.


This construct is not "preferred", it is simply an alternative. I tend
to prefer it and it seems like it could help the op's problem. That`s
why I proposed it.
Jonathan

Aug 18 '05 #7

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

Similar topics

1
by: Donald Firesmith | last post by:
We are converting the OPEN Process Framework Repository (www.donald-firesmith.com) of over 1,100 free open source reusable process components for building development methods for...
3
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to...
10
by: Rada Chirkova | last post by:
Hi, at NC State University, my students and I are working on a project called "self-organizing databases," please see description below. I would like to use an open-source database system for...
3
by: G Patel | last post by:
Hello, If a program has two source files: main.c secondaryfunctions.c and I have a header file: secondaryfunctions.h (with prototypes for the function) The only function in main.c is main()...
1
by: belangour abdessamad | last post by:
Hi, In the metadata for an exe file for example, there is classes organized in namespaces. the GetExportedTypes methods returns all types. I need to get the names of namspaces and to organize...
2
by: Andy Fish | last post by:
Hi, With languages like c# having namespaces, I was wondering what's the recommended practice for reusing source code. I'm not talking big stuff like log4net that's version controlled and...
0
by: Fredrik Strandberg | last post by:
I am trying to figure out how to organize a visual studio vb.net solution to make it possible to execute automated unit tests. I encounter problems when creating stubs. When testing an existing...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
1
by: Ushach | last post by:
hi, I want to know about Self Organizing maps.T ounderstand the concept ,I need a small example which explains how clustering is done through self organizing maps?If any body implemented it plz...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.