Namespaces?

BlitzMax Forums/BlitzMax Programming/Namespaces?

JoshK(Posted 2007) [#1]
This would be nice:
http://en.wikipedia.org/wiki/Namespace_(computer_science)


TheSin(Posted 2007) [#2]
aren't they already in bmax? i thought so.


ziggy(Posted 2007) [#3]
Namespaces are already on BlitzMax.

Example code:
Type Tlist
    Method DoSomething:String(Val:String)
        Return Val
    End Method
End Type

Local Var1:Tlist
Local List:brl.pub.tlist

a namespace in BlitzMax is composed by the modserver name and the module name.
Once you import a module, the full namespace path is not requiered, but you can use it to avoid naming conflicts, like in the example above.

if you import sidesign.minib3d you don't need to write:
sidesign.minib3d.graphics3d(800,600)

becouse in the import statement, the namespace is already selected. So you can make:
graphics3d(800,600)

directly.


JoshK(Posted 2007) [#4]
I thought C namespaces were like this:

Type TFoo
field x,y
EndType

foo:TFoo=new TFoo
Using Foo

x=0
y=1


ziggy(Posted 2007) [#5]
That's not exactly namespaces.


Winni(Posted 2007) [#6]
Definition of namespaces for C#:

http://msdn2.microsoft.com/en-us/library/z2kcy19k(VS.80).aspx

or here

http://www.csharp-station.com/Tutorials/Lesson06.aspx

I believe that the C# definition of namespaces is closer to what most people have in mind when they talk about namespaces these days. The concept that Leadwerks describes is what good old Pascal did with the "with <type> do begin end;" expression.


Picklesworth(Posted 2007) [#7]
A namespace is really just a block with its own unique set of variable names that do not affect others, where "x" variable in one namespace can be created even though there is a different "x" variable in another namespace... right?

So, with that in mind, modules in BlitzMax are all their own namespaces, and local / global variables would be in their own namespaces.

I rather dislike the way C# does it, since Namespaces are tacked on via a new keyword even though things like classes (or modules) would do the same job anyway.
In my opinion, a namespace should be left alone as a thing that happens, but not a thing that is explicitly created.
Of course, my dislike is probably founded on a lack of understanding, so feel free to correct me!


Winni(Posted 2007) [#8]
C# treats namespaces in a way similar to modules. Thanks to using a keyword, you can implement multiple namespaces in one file - something that Java does not allow you to do, for example. By the way, in BlitzMax one does also have to use the "module" keyword, but it does not look as if you could declare multiple modules in one file - there is no "End Module" statement in the language. In C#, the namespace is defined within curly braces like everything else.

In C#, you can implement a multitude of classes with the same name, each in an own namespace. This is different to and more advanced than the "inner class" concept, because an inner class is only known to the class itself, but not to outer classes. So classes do not allow for the same features as namespaces.


Blueapples(Posted 2007) [#9]
Modules are namespaces with the exception that the default namespace consists of all imported modules merged with the current program's namespace. The default behavior happens to be to import all modules, unless you use the Framework keyword. This is why at first glance BMax doesn't appear to have namespace support.

This is actually very similar to how Delphi (Object Pascal) handles it's concept of namespaces, "units". Delphi just doesn't import everything available by default.

Even with several module's identifiers imported into the main namespace, it is still possible to access any overlapping identifiers explicitly by their module "path", or namespace as Ziggy pointed out.

Modules are declared under the mod folder in a particular place directory structure ("mod/ModuleScope.mod/ModuleName.mod" where ModuleScope is your company name and ModuleName is the name of the module, obviously) and begin with the keyword Module:

Module ModuleScope.ModuleName