Re: Do you currently use namespaces?
- Posted by Matt Lewis <matthewwalkerlewis at gmai?.?om> May 26, 2008
- 1084 views
CChris wrote: > > Matt Lewis wrote: > > > > CChris wrote: > > > > > > The core point is that you need to know the name of a file to include it. > > > But you don't know the name of all the third party files that might > > > benefit > > > from including fileB.e, since what is needed is only some properties of > > > the including file. This goes against reusability of fileB.e. > > > > Again, your pattern is broken. You should expose an API for those that use > > your library to supply whatever initialization stuff you need. You also > > get the free bonus that you don't require that more symbols be global. > > The construct is perfectly valid in 3.1, and would serve a definite > purpose, ie implementing plugin file schemes. Perhaps removing this > ability will not actually break code. But I see no benefit to offset > the loss. There is no loss. You can still implement this. It's still a bad idea, and that's why the warning is there. So in reality, there is no loss, and only benefit. Consider the case when some other library that your user uses happens to have some global that has the same name as one that you require the user to implement? Now your library will break if it isn't included first, or if the user modifies your code. I'll say it again. Using this pattern makes it so that your code will play nice with other code. If you're just writing the final application, then you can be assured that your poorly structured code will not mess up anyone else. After all, you can always edit your code. If you're going to release your code for others to use, however, you're creating potential problems if you continue to use this pattern. You don't need to do that for plugins. In fact, this would seem to limit the number of plugins you could use, since you rely on calling discrete things. It would be like hardcoding Window in win32lib as an atom, and having users create their window and store it in that variable. But what if I want two windows in my app? Or, if you still coded it with sequences, and had users append their stuff to some global that you used, you're now doing the opposite of modular coding, since you've coupled the library and the application so closely. Matt