B
Branco Medeiros
Zytan wrote:
Yes, modules do put all public elements in the "global" namespace they
belong.
Note, however, that while a module is usually placed at the project's
namespace, it doesn't need to be so. A module in a specific namespace
won't appear globally in the project's namespace, only in the
immediate namespace the module is contained. Outside the namespace
you'd still need to prefix the method call with the namespace -- or
import the namespace altogether.
<aircode>
Namespace Globals
Module SomeModule
Sub SomeSub
'...
End Sub
End Module
End Module
Class SomeClass
Sub New
SomeSub '<-- Error
Globals.SomeSub '<-- Ok
Globals.SomeModule.SomeSub '<-- Ok, also
End Sub
End Class
'In another file
Imports Globals
Class SomeOtherClass
Sub New
SomeSub '<-- Ok
SomeModule.SomeSub '<-- ditto
End Sub
End Class
</aircode>
If this behavior isn't what you want, I suggest you use shared methods
in classes, then.
On the other side, if "global" methods is exactly what you want, or
you don't care because you'd Import the class anyway (making the
shared methods global), or still, you want global methods inside a
specific namespace, then go ahead and use a module, instead.
HTH.
Regards,
Branco.
<snip>do Modules place everything into the
global namespace? This is what I dislike about them. So, I'll use
classes, instead, for this one reason alone.
Yes, modules do put all public elements in the "global" namespace they
belong.
Note, however, that while a module is usually placed at the project's
namespace, it doesn't need to be so. A module in a specific namespace
won't appear globally in the project's namespace, only in the
immediate namespace the module is contained. Outside the namespace
you'd still need to prefix the method call with the namespace -- or
import the namespace altogether.
<aircode>
Namespace Globals
Module SomeModule
Sub SomeSub
'...
End Sub
End Module
End Module
Class SomeClass
Sub New
SomeSub '<-- Error
Globals.SomeSub '<-- Ok
Globals.SomeModule.SomeSub '<-- Ok, also
End Sub
End Class
'In another file
Imports Globals
Class SomeOtherClass
Sub New
SomeSub '<-- Ok
SomeModule.SomeSub '<-- ditto
End Sub
End Class
</aircode>
If this behavior isn't what you want, I suggest you use shared methods
in classes, then.
On the other side, if "global" methods is exactly what you want, or
you don't care because you'd Import the class anyway (making the
shared methods global), or still, you want global methods inside a
specific namespace, then go ahead and use a module, instead.
HTH.
Regards,
Branco.