Using C++ namespaces in C# namespace style

M

MikeP

Is is OK to use C++ namespaces like namespaces are used in C#? Namely, to
hierarchically organize code. For example:

std::File
std::Container
 
K

Kai-Uwe Bux

MikeP said:
Is is OK to use C++ namespaces like namespaces are used in C#? Namely, to
hierarchically organize code. For example:

std::File
std::Container

Yes, namespaces can be nested. You can, however, not do anything about what
is in std. Your own code base can be organized quite hierarchically.


Best,

Kai-Uwe Bux
 
J

Jorgen Grahn

Yes, namespaces can be nested. You can, however, not do anything about what
is in std. Your own code base can be organized quite hierarchically.

I've even seen namespaces used as what's-its-name in Java:
com::company::division::product_family::product::subsystem::...

Not that I recommend it ...

/Jorgen
 
P

Paul

MikeP said:
Is is OK to use C++ namespaces like namespaces are used in C#? Namely, to
hierarchically organize code. For example:

std::File
std::Container
This depends what you mean by heirarchically organise code.
I see a namespace as more or less the same in both languages although I have
forgot alomost all I knew about C#, but AFAIR it still just a collective
scoping of identifiers.
Its like giving a name to something, an object, function or whatever, a
second name so we can have two Joes. A Joe smith and a Joe Jones for
example.

Heirarchy of code means , to me at least, priveldges and ownership. But I
dont think you mean this, so I'm probably babbling .
 
J

Juha Nieminen

Jorgen Grahn said:
I've even seen namespaces used as what's-its-name in Java:
com::company::division::product_family::product::subsystem::...

Not that I recommend it ...

At some point you might want to create a namespace alias (which is
possible in C++), so that it becomes something like ccdpps::...

Not that it's any more readable, but...
 
S

Stefan Ram

Kai-Uwe Bux said:
Yes, namespaces can be nested. You can, however, not do anything about what
is in std. Your own code base can be organized quite hierarchically.

»... about what is in ::std«. One can declare:
¯¯ ¯¯¯
namespace alpha { namespace std { ...
 
V

Victor Bazarov

Is is OK to use C++ namespaces like namespaces are used in C#? Namely, to
hierarchically organize code. For example:

std::File
std::Container

First off, C# features are off-topic here unless you define what they
mean. You cannot just ask about another language as if it is common
knowledge. What is your definition of "hierarchically organize code"?
What would be the purpose? And what are the trade-offs (if you happen
to have thought of any)?

If you have a problem and a solution in C++, do post it, and let's
discuss. If you just want C++ to be "like <insert the name of another
language>", then stop wasting your time, our time, and the bandwidth.
Either use C++ or use the other language.

V
 
M

MikeP

Victor said:
First off, C# features are off-topic here unless you define what they
mean. You cannot just ask about another language as if it is common
knowledge. What is your definition of "hierarchically organize code"?
What would be the purpose? And what are the trade-offs (if you happen
to have thought of any)?

If you have a problem and a solution in C++, do post it, and let's
discuss. If you just want C++ to be "like <insert the name of another
language>", then stop wasting your time, our time, and the bandwidth.
Either use C++ or use the other language.

Spoken like a true "fanboy". Don't you find it odd that everyone but you
understood the question? It seems you need to do some introspection. And
you're surely not doing C++ any good deed by running your mouth off like
that, FWIW.
 
N

Noah Roberts

Spoken like a true "fanboy". Don't you find it odd that everyone but you
understood the question? It seems you need to do some introspection. And
you're surely not doing C++ any good deed by running your mouth off like
that, FWIW.
*plonk*
 
A

Alf P. Steinbach /Usenet

* MikeP, on 18.04.2011 20:36:
Spoken like a true "fanboy". Don't you find it odd that everyone but you
understood the question?

They guessed.

It apparently so happened that they guessed right about what you had in mind,
but equally easily the could have guessed wrong (we're not telepaths), and then
it would just be a waste of time.

Victor is right, you're wasting our time.

It seems you need to do some introspection. And
you're surely not doing C++ any good deed by running your mouth off like
that, FWIW.

He did not, but you are.

And you're anonymous.

So my guess is, given that Victor is right and posts with full name and is a
moderator of clc++m and has not gone ad hominem and has not employed derogatory
labeling, while your are wrong and posts anonymously and has no standing in the
community and do use ad hominem and has now employed derogatory labeling, given
that, I guess that you're effectively a troll (perhaps you're very young?).


Cheers & hth.,

- Alf
 
J

Jorgen Grahn

Yes, namespaces can be nested. You can, however, not do anything about what
is in std. Your own code base can be organized quite hierarchically.

But like someone else wrote, what's the point?

I think most C++ people stick to a very flat namespace design. Same in
Python. For C# and other languages/cultures which I don't know, I have
no idea what people do, or why.

/Jorgen
 
M

MikeP

Jorgen said:
But like someone else wrote, what's the point?

Code organization. Also, it forces one to think more in terms of
separation of concerns/orthogonality. My guess is that the standard C++
library is all in one namespace because the library (especially the C
part) is so intertwined that nothing but a complete rework could result
in a nice partitioning using namespaces. Had namespaces been in the
though process way back when, and exploited to their potential, a much
nicer standard library might indeed exist. And who doesn't/hasn't
"refactored" at least a part of the standard library (C or C++) at some
time?
I think most C++ people stick to a very flat namespace design.

That's "neither here nor there". The question is what the best practices
are (for new code). Orthogonality is good. That "most people do flat" (if
that is the case) may mean that most programmers are novice designers
(probably true).
Same in
Python. For C# and other languages/cultures which I don't know, I have
no idea what people do, or why.

I ventured a guess above. Actually two, if you count that "legacy" code
can't really take advantage of namespaces to any real extent.
 
A

Alf P. Steinbach /Usenet

* MikeP, on 20.04.2011 05:40:
Code organization. Also, it forces one to think more in terms of
separation of concerns/orthogonality. My guess is that the standard C++
library is all in one namespace

it isn't

because the library (especially the C
part) is so intertwined that nothing but a complete rework could result
in a nice partitioning using namespaces.

the "because" is wrong. the standard library was defined in the same process
that introduced namespaces

Had namespaces been in the
though process way back when

they were, see above

, and exploited to their potential, a much
nicer standard library might indeed exist. And who doesn't/hasn't
"refactored" at least a part of the standard library (C or C++) at some
time?

you would have to define '"refactored"' to get any meaningful answer to that

for the second time

your readers are not telepaths


That's "neither here nor there". The question is what the best practices
are (for new code). Orthogonality is good. That "most people do flat" (if
that is the case) may mean that most programmers are novice designers
(probably true).


I ventured a guess above. Actually two, if you count that "legacy" code
can't really take advantage of namespaces to any real extent.

it's not uncommon to nest namespaces

neither is it very common

check out libraries like boost
 
I

Ian Collins

* MikeP, on 20.04.2011 05:40:

you would have to define '"refactored"' to get any meaningful answer to that

Using the normal definition of refactor, what he proposes is the
opposite! Refactoring modifies the code without changing its behaviour
or interface.
 
M

MikeP

Alf said:
* MikeP, on 20.04.2011 05:40:

it isn't

You are missing "my point" (of being in C# land for the last week and
"liking it"(don't ask why I don't like it)). I know what C++ is and I
told you many years ago I don't like that camel process having come out
of "parallel" world", but y'all keep on doing the same thing, so I know
you, can research you, and find you all over the place. Someone said
something about <something> and getting the same result, but persisting
with that (someone chime in with the annecdote please).

I don't like that. And I won't play.
the "because" is wrong. the standard library was defined in the same
process that introduced namespaces

Did you just say: "the world is flat"? Dude, ...
they were, see above
Dude...


you would have to define '"refactored"' to get any meaningful answer
to that


for the second time

your readers are not telepaths

I assure you my quest for reassurance was answered long ago and that your
straggling banter about whatever is off-topic in MY post. (And I have
not "readers").

And shut your mouth with "for the second time".
it's not uncommon to nest namespaces

neither is it very common

check out libraries like boost

I don't feel sorry for you.

I am not you.
 
A

Alf P. Steinbach /Usenet

* MikeP, on 20.04.2011 07:32:
You are missing "my point" (of being in C# land for the last week and
"liking it"(don't ask why I don't like it)).

wtf do you mean
 
M

MikeP

Alf said:
* MikeP, on 20.04.2011 07:32:

wtf do you mean

Do you mean seriously or jokingly? On the serious side, I haven't
programmed in C# until a week ago and it is quite fine for doing the
"quick and dirty" program (probably more than that). On the namespace
thing, that level of organization capability beyond classes and files is
nice, and C# is one example of such usage. So, just simple thoughts.
 
J

Jorgen Grahn

Jorgen Grahn wrote: ....

That's "neither here nor there". The question is what the best practices
are (for new code). Orthogonality is good. That "most people do flat" (if
that is the case) may mean that most programmers are novice designers
(probably true).

I just stated what I /think/; didn't claim to answer any particular
question or to be right. (And by "very flat" I meant a handful of
namespaces, occasionally nested one level.)

/Jorgen
 
M

MikeP

Jorgen said:
I just stated what I /think/; didn't claim to answer any particular
question or to be right. (And by "very flat" I meant a handful of
namespaces, occasionally nested one level.)

I don't mind a bunch of namespaces if/when it is appropriate. Flat (as in
most at the same level) occurs naturally though. .Net is pretty flat,
e.g., but has a lot of namespaces. Flat especially if you consider that
the "System" namespace could have been an unnamed global namespace. My
own code uses the global namespace as a "level zero" upon which all other
namespaces are built on top of. I don't see any value in having "level
zero" in a named namespace and find it "unwieldly" to do so. Anyway, one
reason to keep namespace hiearchies flat is to keep complexity of usage
low (less to remember: "now in what namespace did that class get tucked
away?". OTOH, the C++ standard library is too flat for my liking. If all
you want is to keep different developers from walking on each other, then
the One Big Namespace style is fine; I consider that pretty much not
using namespaces though for it gives no benefit to code developed and
used by one developer/team/company (save for keeping it distinct from the
standard library names).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top