Ok, I’m a little confused but I know you guys know the answer
Say I have script A and it executes a ‘require’ for module B and module C.
Now lets say that within module B there is also a require for module C that
executes.
Do I now have two copies of module C loaded in two seperate namespaces? Or
is there no harm in this and pretty much the norm?
require checks the filename, and skips if the file already is loaded.
namespace doesn’t have impact on require.
···
On Tue, 30 Mar 2004 22:33:26 +0000, Greg Brondo wrote:
Ok, I’m a little confused but I know you guys know the answer
Say I have script A and it executes a ‘require’ for module B and module C.
Now lets say that within module B there is also a require for module C that
executes.
Do I now have two copies of module C loaded in two seperate namespaces? Or
is there no harm in this and pretty much the norm?
Ok, I’m a little confused but I know you guys know the answer
Say I have script A and it executes a ‘require’ for module B and module
C.
Now lets say that within module B there is also a require for module C
that
executes.
The wording is not quite correct: you should say “script A requires file
B”, because require is agnostic of modules. It just knows files. Of
course there is this convention to put a module into a file, but a
required file need not contain a single module - it can be any non
negative number of modules, classes, methods, variables - just a normal
script.
Do I now have two copies of module C loaded in two seperate namespaces?
Or
is there no harm in this and pretty much the norm?
Require ensures that each file is loaded only once. And it is loaded into
the top namespace, i.e. it makes no difference whether you do
require ‘B’
module A
end
or
module A
require ‘B’
end
although I recommend the first version to avoid confusion.
On Tue, 30 Mar 2004 22:33:26 +0000, Greg Brondo wrote:
Ok, I’m a little confused but I know you guys know the answer
Say I have script A and it executes a ‘require’ for module B and module
C. Now lets say that within module B there is also a require for module C
that executes.
Do I now have two copies of module C loaded in two seperate namespaces?
Or is there no harm in this and pretty much the norm?
require checks the filename, and skips if the file already is loaded.
namespace doesn’t have impact on require.