Namespace: right and wrong between PHP and Node.js
I have learned both PHP and Node.js, there are something I want to say according to the design of the concept `namespace` in both of the two languages.
* It is right that Node.js has no `namespace` keyword
When in old times (c or c++), we compile the source files into several object files, and then into the target execute or library. Cause several sources will be compiled into one, they need a separate name to distinguish the components (we name it "name conflicts") when the project goes large. So c++ comes with namespaces.
When PHP adds OOP concepts, it also follows those famous programming languages: it adds the `namespace`. Just like the thing we all know, then there also comes the autoload -- mapping from the `namespace/class` to the source file, so that when you add `use Foo\Bar;` , PHP could know where the class can be loaded.
But PHP itself is a scripting language, the directory actually can be the natural namespace. Node.js does the smart things, it just do `var Bar = require("Foo/Bar");`, everything is fine. Actually, not just the scripting language, as you can see, golang also treats the directory as a natural separator of the components.
* It is right that PHP has two levels in `vendor` directory
The thing is very funny. Because PHP does have `namespace` keyword, and for one author, it is very easily that the guy does two packages and put them into one vendor name. Ex.: if he (me, "Yarco"), did two packages "Foo" and "Bar", and then they will be both saved under "yarco" directory (there exists a mapping from "Yarco" to "yarco"). So actually, the packages are grouped by vendor names, here "yarco".
Then let's turn back to see Node.js, if you've installed, for example, webpack module, when you look into `node_modules` directory, you got shocked. Oh man, what is those? (See the cover image of this article). It has only one level.
Conclusion: in modern programming languages design, we don't need `namespace` keyword anymore, directory can be the natural separator; And the same time, the concept of `namespace` is still there, when thinking about the packages layout, you should take `vendor` names into the account.