views:

116

answers:

3

Files and directories could have different namespaces, and still be used to identify specific files, because a file and directory with the same name can be distinguished by being different kinds of things.

Primitive field and reference fields could also have different namespaces (in Java), because if a primitive and a reference field had the same name, they could be identified by being different kinds of things.

Separate namespaces are used elsewhere like this. For example, in Java, you can have a method exampleName() and a field exampleName, and though they have the same name, they are distinguished by being different kinds of things.

+2  A: 

First, this question is language specific. In pure OOP languages there's no distinction between atomic and compound elements. Everything is an object. By a similar reason in a pure functional language you can't have function and variable named the same.

Second, if you have polymorphic operations, there's no way to tell which variable did you refer to. For example, you can't have different namespaces for files and directories, because of the polymorphic operations, like

cp foo bar

The cp works on files and dirs, and if you have different namespaces, there's no way to tell what did you mean.

Igor Krivokon
Yes, this is a factor: if there are different namespaces, you need to indicate which namespace you mean. In my example of fields vs. methods, the "()" distinguishes plays this role. For your "cp" example, it could be done by appending a "/ for directories, eg: cp foo/ bar/ Whether that's worth the hassle becomes the issue.
13ren
+1  A: 

I do not believe that this would be a good idea. I imagine that the reasons involve things like performance and simplicity of the filesystem code. If a directory listing had to go down 2 or 3 or more different paths depending on how many different namespaces you think you should have, this would probably complicate the code.

Additionally, consider the end user confusion that might arise. Currently we have a kind of namespacing available in filesystems by using file extensions. You can have file.txt and file.dll and file.exe all existant in the same directory. What happens when these files are present simultaneously is a matter of concern - this has been one method for virus writers to use a form of social engineering to get you to click on the wrong file. Imagine if you could confuse a directory with a file of the same name as well?

1800 INFORMATION
For performance, I don't think it would be an issue: the system must need to know which kind you are seeking before looking it up (consider if two had the same name). Therefore, it would know which namespace to look in before doing the look up. For confusion, I think something like that is probably the reason.
13ren
A: 

Directories and files aren't necessarily so different. They are both entries in their parent directory, just with a flag to indicate if an entry is a directory or not. You can open a directory and read it just as if it was a file, just that certain other operations are possible on it- symbolic links work the same way. (This description is biased towards the Unix filesystem view, but I think the DOS/Windows view works much the same way). Within any directory, there is a set of names of members, and the filesystem enforces the uniqueness constraint that a directory can only have one member with a given name.

Thinking about Java method names compared to field names--- back in C, you couldn't have a global function and global variable with the same name, because all the symbols in the object file are in a single namespace. But you could with C++, because a function "void foo()" was mapped to mangled symbol name ("foo__vv" or something). So it's not so much that they have a separate namespace, as that the key into the namespace is different for a field "foo" vs a method "foo()". Given that you can't get key clashes, they look like separate namespaces, but is that really how it's implemented?

araqnid
I'm using namespacing to refer to an effect, not a specific implementation. Provided names in different namespaces don't affect each other, then they are in separate namespaces. You can implement it with name munging (like "foo_w"), or with separate hashtables, or probably in other ways.
13ren
I agree directories and files aren't so different - they can be put in the same namespace. But they could also be put in different namespaces (which gives you more freedom - a file and dir can have the same name). My question is, what are the reasons for doing the former?
13ren