For example, I have the function generate_salt() in encryption.file but the person may not know where generate_salt() is from. Using a namespace like encryption::generate_salt(), or encryption_generate_salt() for every function in the encryption.file. Or would it be a waste of space and typing because some IDEs can navigate you to the function?


YES. Unless your code is stored in an opaque binary file, any operating system you could program on can scan text files for a function declaration.

Now, namespaces themselves are excellent tools in any language that supports them. But a large part of their utility is that they help make code polymorphic. You can replace the entire encryption namespace without needing to hunt through your code, and with excellent tools even change the namespace entirely in a single action.

But the "namespaces" is not necessarily going to map to a specific file. You may need to import them from a library, or have a namespace contained in several text files. And you may need to change these later on, and if the functions are named for their files you wind up with either an artificial restriction or an inconsistency, neither of which make anyone's lives easier.

(naming your FILES and DIRECTORIES for the functions they hold is a different matter, and is a very good idea. Because you might develop each function in its own file, and later combine or re-seperate them.)

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.