473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When to use a namespace

Consider

// file fft_data.h
class FFT_DATA
{
public:

static const unsigned int Data_Words = 10;
struct Data_Block_Type
{
unsigned short word[ Data_Words ];
unsigned short checksum;
bool valid;
};
// 4 more structs and thats it for fft_data
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.
Thanks for your time.
Jul 22 '05 #1
8 1530
ma740988 wrote:
Consider

// file fft_data.h
class FFT_DATA
{
public:

static const unsigned int Data_Words = 10;
struct Data_Block_Type
{
unsigned short word[ Data_Words ];
unsigned short checksum;
bool valid;
};
// 4 more structs and thats it for fft_data
Doesn't seem to have any *data*, does it?
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
Shouldn't that be 'static' or does it use some data members that you
decided to omit?
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
More appropriate for what? You can't create instances of namespaces.
You didn't explain at all whether you want to do that. You can't
inherit from a namespace either.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.


What member data? Did you mean to say "static data"?

And, yes, if a struct has data and no member functions, it's OK.

Victor
Jul 22 '05 #2
"ma740988" <ma******@pegas us.cc.ucf.edu> wrote in message
news:a5******** *************** **@posting.goog le.com...
Consider

// file fft_data.h
class FFT_DATA
{
public:

static const unsigned int Data_Words = 10;
struct Data_Block_Type
{
unsigned short word[ Data_Words ];
unsigned short checksum;
bool valid;
};
// 4 more structs and thats it for fft_data
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.


If you'd never create an instance of FFT_DATA and everything contained
inside of it is "open to the public", then it should probably be a namespace
instead of a class. However, in practice, there isn't much harm done in
leaving it as a struct. Sometimes you do need a struct instead of a
namespace. For instance, class templates sometimes delegate some work to
static members of a configurable type, and in that case, you can't use a
namespace.

--
David Hilsee
Jul 22 '05 #3
Victor Bazarov <v.********@com Acast.net> wrote in message news:<hb******* ********@newsre ad1.dllstx09.us .to.verio.net>. ..
ma740988 wrote: [snip]
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
Shouldn't that be 'static' or does it use some data members that you
decided to omit?

I didn't omit any member data and I'm not sure of what leads you to
believe that the returned type should be static.
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.


More appropriate for what? You can't create instances of namespaces.
You didn't explain at all whether you want to do that. You can't
inherit from a namespace either.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.


What member data? Did you mean to say "static data"?


I suspect I erred in referring to Data_Words as 'member data' since
you seem to ramble on, on a continuum about data.

I chose the wrong class to use as my example since it only contained '
static data'.
And, yes, if a struct has data and no member functions, it's OK.

I suspect the same can be said for the 'class' - per my initial
example - since struct/class are somewhat interchangable.
Jul 22 '05 #4
ma740988 wrote:
Victor Bazarov <v.********@com Acast.net> wrote in message news:<hb******* ********@newsre ad1.dllstx09.us .to.verio.net>. ..
ma740988 wrote:
[snip]

};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();


Shouldn't that be 'static' or does it use some data members that you
decided to omit?


I didn't omit any member data and I'm not sure of what leads you to
believe that the returned type should be static.


I am not sure what leads you to believe that specifying a member function
'static' has anything to do with its return type. Could it be you have
no idea what 'static' does to a member function?

};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
More appropriate for what? You can't create instances of namespaces.
You didn't explain at all whether you want to do that. You can't
inherit from a namespace either.

It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.


What member data? Did you mean to say "static data"?

I suspect I erred in referring to Data_Words as 'member data' since
you seem to ramble on, on a continuum about data.


I am not sure I understand the sentence above. Do you by any chance
understand the importance of "member data"? Why do we have member data
in classes at all? Do you know the difference between static and non-
static data members? If you answered "no" to any of these questions,
take a course on C++, or at least get back to your favourite C++ book.
[..]

Jul 22 '05 #5
Victor Bazarov <v.********@com Acast.net> wrote in message news:<yx******* ********@newsre ad1.dllstx09.us .to.verio.net>. ..
ma740988 wrote:
Victor Bazarov <v.********@com Acast.net> wrote in message news:<hb******* ********@newsre ad1.dllstx09.us .to.verio.net>. ..
[...]
I am not sure what leads you to believe that specifying a member function
'static' has anything to do with its return type. Could it be you have
no idea what 'static' does to a member function?
This has absolutely nothing with my understanding of static member
function but more importantly what YOU initially wrote. i.e...

[V Bazarov]Shouldn't that be 'static' or does it use some data members that you
decided to omit? [/V Bazarov]

Perhaps I should have asked for clarification. i.e. Shouldn't 'that'?
'that' what?

My interpretation per your question was as follows:

class FFT_DATA
{
public:
static Data_Block_Type // Note: I added 'static' to Data_Block_Type
{
};
};

// later
class FP_SP_INTERFACE
{
public:
FFT_DATA::Data_ Block Do_A_Special_Th ing();
};

Alternatively, your questions could have been interpreted as:
static FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
Do_A_Special_Th ing should be a static member function. IOW add static
in front of the return type. I chose the former interpretation.

[...]
I am not sure I understand the sentence above. Do you by any chance
understand the importance of "member data"? Why do we have member data
in classes at all? Do you know the difference between static and non-
static data members? If you answered "no" to any of these questions,
take a course on C++, or at least get back to your favourite C++ book.


Let me re-iterate again. This has absolutely NOTHING to do with my
understanding of the importance of member data among other things.

You rambled on about 'data' in your initial post. Of interest, lets
re-visit two of your initial questions.

1) Doesn't seem to have any *data*, does it?
2) What member data? Did you mean to say "static data"?
In my initial post I used the term 'member data' - on a 'broader
scale' - in an attempt to understand the impetus behind (more of a
design question) having a CLASS with just member data (static and non
static) and composite types? IOW. Why not a namespace.
Unfortunately FFT_DATA contained no 'non static member data' and I
erred in referring to Data_Words as member data as opposed to static
member data.

Perhaps FFT_DATA would have been more appropriate for you if I had.

class FFT_DATA
{
public:
int Idx; // member data
static int Jdx; // static member data
};
In the end I don't need your recommendations with regard to a course
or resorting to my favorite book on C++. At the graduate level, my
program of study may not entail C++, but after an undergraduate course
and reading texts, I'm comfortable enough with various aspects of the
language. I might not be able to quote the standard and am clueless
when it comes to libraries such as 'boost' (rumor has it, boost might
be included with the next 'revision') but I feel - linguistics aside
- it's important for me - at this point to know/use the right 'tools'
(especially those algorithms) for the job.

Indeed, finding and using the right tools for the job is oft easier
said that done, especially when working in 'teams': Just ask 'John
Doe' :
1) Why he used an array as opposed to std::vect
2) Why muck with char* when you have std::string.

Occassionally this turns into an arm wrestling match with plenty of
verbiage about 'what's better' etc. etc.

By the way. David Hilsee provided a detailed explanation which
answered my question. That said, we could move on.

Thanks for you time.
[..]

Jul 22 '05 #6
David Hilsee wrote:
"ma740988" <ma******@pegas us.cc.ucf.edu> wrote in message
news:a5******** *************** **@posting.goog le.com...
Consider

// file fft_data.h
class FFT_DATA
{
public:

static const unsigned int Data_Words = 10;
struct Data_Block_Type
{
unsigned short word[ Data_Words ];
unsigned short checksum;
bool valid;
};
// 4 more structs and thats it for fft_data
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.

If you'd never create an instance of FFT_DATA and everything contained
inside of it is "open to the public", then it should probably be a namespace
instead of a class. However, in practice, there isn't much harm done in
leaving it as a struct. Sometimes you do need a struct instead of a
namespace. For instance, class templates sometimes delegate some work to
static members of a configurable type, and in that case, you can't use a
namespace.


To me, a namespace should be used if the visibility of some entities
need to be confined to a group of classes, or a group of functions. In
the example above, the structs could have just as well been defined in
class FP_SP_INTERFACE , couldn't they?

If there were several classes that would like to share the definition of
the structs, as well as the static variable, then yes, they should all
go into a namespace.
Jul 22 '05 #7
"Dave Rahardja" <as*@me.com> wrote in message
news:rS******** ***********@twi ster.rdc-kc.rr.com...
David Hilsee wrote:
"ma740988" <ma******@pegas us.cc.ucf.edu> wrote in message
news:a5******** *************** **@posting.goog le.com...
Consider

// file fft_data.h
class FFT_DATA
{
public:

static const unsigned int Data_Words = 10;
struct Data_Block_Type
{
unsigned short word[ Data_Words ];
unsigned short checksum;
bool valid;
};
// 4 more structs and thats it for fft_data
};

later

# include "fft_data.h "
class FP_SP_INTERFACE
{
public:

FFT_DATA::Data_ Block_Type Do_A_Special_Th ing();
};

Would a namespace be more appropriate here? If the answer depends,
then I'm confused on what.
It also appears 'odd' to me to have a class comprised SOLEY of
composite types and member data.

If you'd never create an instance of FFT_DATA and everything contained
inside of it is "open to the public", then it should probably be a namespace instead of a class. However, in practice, there isn't much harm done in
leaving it as a struct. Sometimes you do need a struct instead of a
namespace. For instance, class templates sometimes delegate some work to static members of a configurable type, and in that case, you can't use a
namespace.


To me, a namespace should be used if the visibility of some entities
need to be confined to a group of classes, or a group of functions. In
the example above, the structs could have just as well been defined in
class FP_SP_INTERFACE , couldn't they?

If there were several classes that would like to share the definition of
the structs, as well as the static variable, then yes, they should all
go into a namespace.


I don't think I understand your comment about visibility. To me, a
namespace is usually not used to confine visibility. Namespaces are
generally used as a logical grouping of functionality. Namespaces are "wide
open" when it comes to visibility. That is why I added that bit about
everything being "open to the public."

I agree that the structs could have been declared inside FP_SP_INTERFACE ,
but I thought that ma740988 was asking if FFT_DATA should be a namespace
instead of a class. From the little bit of code that was provided, it
seemed to me that FFT_DATA was not being used to define a type of which
instances would be used. Instead, it was being used to group some common
functionality. For that usage, it sounded like a namespace was more
appropriate. Did I misunderstand you?

--
David Hilsee
Jul 22 '05 #8
"David Hilsee" <da************ *@yahoo.com> writes:

[...]
I don't think I understand your comment about visibility. To me, a
namespace is usually not used to confine visibility. Namespaces are
generally used as a logical grouping of functionality. Namespaces are "wide
open" when it comes to visibility. That is why I added that bit about
everything being "open to the public."


The general prupose of namespaces is to avoid nameclashes. The
properties of structuring code is a kind "side effect" :-)

Kind regards,
Nicolas

--
| Nicolas Pavlidis | Elvis Presly: |\ |__ |
| Student of SE & KM | "Into the goto" | \|__| |
| pa****@sbox.tug raz.at | ICQ #320057056 | |
|-------------------University of Technology, Graz----------------|
Jul 22 '05 #9

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

Similar topics

3
1535
by: Joseph A Romeo | last post by:
I have written an XSLT transformation on an ASP.NET page. The resulting HTML is primarily a table of links. I have found that when the resulting HTML is less than or equal to 16040 bytes, the output display is normal, but when the resulting HTML exceeds 16040 bytes, the output does not display correctly. When I look at View Source, I see that the final </html> tag gets moved to another spot in the output, byte by byte as I increase the...
0
1224
by: Joseph A Romeo | last post by:
I have written an XSLT transformation on an ASP.NET page. The resulting HTML is primarily a table of links. I have found that when the resulting HTML is less than or equal to 16040 bytes, the output display is normal, but when the resulting HTML exceeds 16040 bytes, the output does not display correctly. When I look at View Source, I see that the final </html> tag gets moved to another spot in the output, byte by byte as I increase the...
2
2882
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
4
11806
by: Sebastien Tardif | last post by:
Subject: XmlSerializer.Deserialize complain when root declare the namespace If I do XmlSerializer.Deserialize( myString ) and myString is: String myString = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocumentResponse ><documentSize xmlns=\"urn:webservices.docharbor.com\">23</documentSize></DocumentResponse>"; It's working
4
1693
by: Flare | last post by:
OK. I'll try explain my problem so simple as possible. I have to send a complex data type to a WebService from a Asp.net webapplication. My Data type look like this. (A class with a porperty) ------------- namespace Elsam.Turabs.ClassLibraries.TurabsLogExeption{
19
1853
by: Tiraman | last post by:
Hi , I have an assembly that hold few class and few imports which are not used in all of the class's . so my question is when to use the "Imports XXX" And when to use this kind of statement Dim X as New System.XXX ....
2
1972
by: Jeff Brown | last post by:
Hi, I suspect that this isn't possible, but I figured I'd ask. My project has a root namespace, let's say it's "Root", that applies to almost every source file (which is why I've set it as the project's root namespace). However, the project also includes a couple of source files whose contents will live in an entirely different namespace, let's say the "Special"
3
5076
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb). I changed the data type for the structure that contains the XML data from the default "String" to "xml.xmldocument" to enable easy filling of the data. my client code creates an XML document class, fills the data using standard xml dom...
0
2260
by: selvialagar | last post by:
i did a program in vc++.net for ICMP communication using sockets.But when i execute it i received a very slow response...is there any configuration to be made on the server..or any other thing?.. i don't know the reason for slow response...i included the code for this...plz solve my problem... // pingnew.h #pragma once using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Net;
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.