Question about namespaces.

P

Peter Kirk

Hi,

there is a logging service called "log4net". It uses namespaces such as
"log4net" and "log4net.Appender".

If I am writing my own software, would it be considered bad style to use
namespaces like log4net and log4net.Appender in my own code (given that
log4net is well-known product)?

I am using some 3rd party software which does just this. They use log4net in
their product, and have written some of their own code in the
log4net.Appender namespace. Should I expect to see other classes in the
System namespace?


Peter
 
M

Marina Levit [MVP]

My person opinion is that this is just strange to do. Typically, the
company name will start off a namespace - it seems wrong to start off
something you wrote with some other company's namespace.
 
M

Michael Nemtsev

Hello Peter,

PK> there is a logging service called "log4net". It uses namespaces such
PK> as "log4net" and "log4net.Appender".
PK> If I am writing my own software, would it be considered bad style to
PK> use namespaces like log4net and log4net.Appender in my own code
PK> (given that log4net is well-known product)?

It's ok. If you are so conserning about styling, wrap using log4net to the
YourApp.Common namespace and include it only.

PK> I am using some 3rd party software which does just this. They use
PK> log4net in their product, and have written some of their own code in
PK> the log4net.Appender namespace. Should I expect to see other classes
PK> in the System namespace?

Not clear. Could u describe it more wide?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
P

Peter Kirk

Michael Nemtsev said:
Hello Peter,

PK> there is a logging service called "log4net". It uses namespaces such
PK> as "log4net" and "log4net.Appender".
PK> If I am writing my own software, would it be considered bad style to
PK> use namespaces like log4net and log4net.Appender in my own code
PK> (given that log4net is well-known product)?

It's ok. If you are so conserning about styling, wrap using log4net to the
YourApp.Common namespace and include it only.

PK> I am using some 3rd party software which does just this. They use
PK> log4net in their product, and have written some of their own code in
PK> the log4net.Appender namespace. Should I expect to see other classes
PK> in the System namespace?

Not clear. Could u describe it more wide?

Here's an example:
I am writing a control system which has some text processing capabilities.
So I write a class, starting:

namespace System.Text
{
...

I would call this bad style, but I wanted to hear some other opinions.
 
N

Nick Hounsome

Peter Kirk said:
Here's an example:
I am writing a control system which has some text processing capabilities.
So I write a class, starting:

namespace System.Text
{
...

I would call this bad style, but I wanted to hear some other opinions.

It's not a matter of style. It's just stupid.

Firstly, if Microsoft add a class to System.Text with the same name as yours
then all your code will break and secondly, you will confuse anyone who has
the misfortune to maintain your code because they will be wondering why some
classes in System.Text don't appear in the MS help or any book that they
have ever read.

The whole point of namespaces is to prevent this.
 
O

Otis Mukinfus

Here's an example:
I am writing a control system which has some text processing capabilities.
So I write a class, starting:

namespace System.Text
{
...

I would call this bad style, but I wanted to hear some other opinions.
You're right. using System.Text for one of your namespaces is a sure road to
disaster, as would be using another companies namespace. I's probably not
illegal, but think of the headaches it could cause you and the users of your
product.

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
M

Mike Schilling

Nick Hounsome said:
It's not a matter of style. It's just stupid.

Firstly, if Microsoft add a class to System.Text with the same name as
yours then all your code will break and secondly, you will confuse anyone
who has the misfortune to maintain your code because they will be
wondering why some classes in System.Text don't appear in the MS help or
any book that they have ever read.

The whole point of namespaces is to prevent this.

It's actually a bit worse than that. Any file that uses classes from
System.Text probably begins

using System.Text;

If it compiles against an assembly that contains your classes, it has now
imported your class name without knowing it. So even people who *aren't*
specifically maintaining your code will be confused by System.Text.XXX
classes that aren't documented where expected.
 
M

Michael Nemtsev

Hello Peter,

Don't do this. There are a guideline how to name your namespace it's <Company>.<Project>.<Module>
In your case it could be PeterCorporation.CoolSystem.Processing and call
you class "Text"
PK> Here's an example:
PK> I am writing a control system which has some text processing
PK> capabilities.
PK> So I write a class, starting:
PK> namespace System.Text
PK> {
PK> ...
PK> I would call this bad style, but I wanted to hear some other
PK> opinions.
PK>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

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

Top