How to avoid ClassName.ClassName

Monkey Forums/Monkey Beginners/How to avoid ClassName.ClassName

Hero(Posted 2015) [#1]
Hi,

From other programming languages I am used to work with one file for each class. In monkey I found that means when I want to instantiate something I need to write

Local myObj:ClassName.ClassName = New ClassName.ClassName()


Is there a way around this so I can just use

Local myObj:ClassName = New ClassName()


And still be able to have one file for each class? Additionally is my asumption correct that monkey does not support namespaces?


MikeHart(Posted 2015) [#2]
Yes, absolutely. Look at my framework, I do it basically always there.


Hero(Posted 2015) [#3]
I took at look at how it is done in IgnitionX because I have it already installed. Basicly the author seems to have a naming convention where every regular class starts with a lower case i and Interfaces with an upper case I, as seen in this example:

	Class iGraph Extends iEngineObject Implements IMover


The file name is graph.monkey. I believe the author does this to avoid the issue i am having when calling the file name the same as the class name.
Do you handle it the same way in your framework?


tiresius(Posted 2015) [#4]
I thought you could do this with just all lower-case filenames for your monkey modules, since it is case sensitive.
Sorry I'm not at home to test this theory.


MikeHart(Posted 2015) [#5]
For an example, I have the class ftObject which is located inside the cftObject.monkey file.

With my framework, you import one file

fantomEngine.monkey.

This file imports all the other files. Each other file Just imports the fantomEngine.monkey file. This way, all classes are visible for each other.


ImmutableOctet(SKNG)(Posted 2015) [#6]
Different people have different styles for naming their modules and classes. However, modules are implicit namespaces in Monkey. To allow for explicit name resolution, you can refer to the module-name (Namespace). Basically, you get a name conflict at the global "namespace". To fix this, you need a different name for your module, compared to its contents. The standard way of doing this is to either use lowercase names for modules, or to use different names. The way I look at it, you should use lowercase names when the module (File) is mainly the class with the same name. Otherwise, I name them as I see fit (Usually lowercase).

It's really more of a stylistic choice, but you just need to make sure you don't have name conflicts.


Gerry Quinn(Posted 2015) [#7]
The usual approach is:

' File "classname.monkey" contains ClassName class

import classname

Local cn:ClassName = New ClassName()