Should namespace hierarchy reflect the folder hierarchy on the disk

  • Thread starter Thread starter HalcyonWild
  • Start date Start date
H

HalcyonWild

I did try to search this in old posts, but could not find it.

I suppose it is ok to ask beginner level questions here, unlike other
groups, demarcated for beginners and experts.

Suppose I create a class in a namespace, MyNamespace.Trials.

Now, should I create a folder on the disk, like
c:\csprogs\MyNamespace\Trials and keep the generated files there. Or I
can keep them anywhere on the disk.

Also, once I tried making a simple geometry point class, and it would
not compile.

class CSPoint
{
int x;
int y;
//ideally should be double, in a 3d space,
//but just for testing sake, it is 2 ints in a plane

//getter and setter methods.
}

I needed to add a Main. Why is this so.

I come from a Java background.
Thanks.
 
HalcyonWild,

I tried using that heiarchical structure, but I found that it was overly
complicated for projects to reference each other in a solution.

I flatten the heiarchy, and have one directory for each distinct
namespace, so my solution directories will have the following project
directories:

Casper
Casper.Remoting
Casper.Drawing

And so on. In your case, you would have a MyNamespace directory, as
well as a MyNamespace.Trials directory. It will make it much easier as you
have more namespaces, and they start referencing each other.

Hope this helps.
 
HalcyonWild said:
Suppose I create a class in a namespace, MyNamespace.Trials.
Now, should I create a folder on the disk, like
c:\csprogs\MyNamespace\Trials and keep the generated files
there. Or I can keep them anywhere on the disk.

There is no such technical restriction (you can keep them anywhere), but it
is widely regarded as a good practice and makes things easier to find.
Also, once I tried making a simple geometry point class, and it would
not compile. I needed to add a Main. Why is this so.

Your project type was an executable, rather than a class library.
Executables need an entry point.
 
Chris said:
There is no such technical restriction (you can keep them anywhere), but it
is widely regarded as a good practice and makes things easier to find.


Your project type was an executable, rather than a class library.
Executables need an entry point.


Thanks for the quick responses, Chris and Nicholas,

So as I understand it, it is not a restriction from the language side,
to maintain namespace hierarchy in the paths on the disk. But we do it
just for easy maintainability.

So I can keep all my .exe files at one place on the disk, even though
the namespaces are different. I should however maintain folder
hierarchy on disk for easy tracking. Please correct me if I am wrong.

I think that must be a compiler switch, to compile a .cs into a class
library rather than executable. Will look for it. Also Chris, I do not
have visual studio.net. I am using the cmdline compilers with the
framework.

Also, assemblies are something like jars, (from what I searched and
found, not really sure about this), and you normally name assemblies
like namespaces, as a good practice. More questions on this later if I
have any problems. I will try this out.

Thanks.
 
Chris said:
There is no such technical restriction (you can keep them anywhere), but it
is widely regarded as a good practice and makes things easier to find.


As an afterthought, I think this is a great feature. No need to take
care of classpaths, imports , package hierarchies on disk, like in
Java.
 
Back
Top