Creating a Module.

Monkey Forums/Monkey Programming/Creating a Module.

Paul - Taiphoz(Posted 2012) [#1]
whats the steps required, I know from my very limited experience with monkey that its not the same Blitzmax.

Could some one that's made a module for monkey walk me through it, thinking about creating one and just wana check if there is anything special I need to do or know before I start.


Samah(Posted 2012) [#2]
Monkey doesn't really have the concept of "modules", per se. Basically just create your .monkey file(s) in a directory and put it in your modules dir. The modules dir actually means "code_used_everywhere".

This is the easiest way to set it up:
MonkeyPro\
  modules\
    mymodule\
      mymodule.monkey
      file1.monkey
      file2.monkey


mymodule.monkey:
Import file1
Import file2


file1,file2.monkey:
Any other code your module needs.

Your program source that uses the "module":
Import mymodule



AdamRedwoods(Posted 2012) [#3]
Something else I discovered about monkey was that if you name your module the same as your class, use different casing or you'll get errors.
My rule of thumb is to lower-case files, but use Upper-Case classes.

"vector.monkey" file:
Class Vector

    '' not "vector"

End



Samah(Posted 2012) [#4]
This is why having a naming standard is brilliant. You can usually guess what an identifier is based on its case. When doing peer reviews on Java code, I fail anything that doesn't match Java naming conventions.


ziggy(Posted 2012) [#5]
@AdamRedwoods: That's becouse module name can be used also in source code. In your example, if both were called vector, this word would be the name of the class and the name of the module containg the class, and this would be ambigous:

Alias myname = vector;

What is "vector" refering to? the class or the module?

Also, notice you can use module names as prefix for classes, to avoid name clashes, so your class would really be vector.vector
It is a good idea to follow the language naming comvention wich is:

Monkey naming conventions

The standard Monkey modules use a simple naming convention:
• All-caps case (eg: 'ALLCAPS' ): Constants.

• Pascal case (eg: 'PascalCase' ): Globals, functions, class, methods, properties.

• Camel case (eg: 'camelCase' ): Fields, locals and function parameters.

It is not stated in the documentation, but module names are lowercase, as seen on all official language samples. Maybe we should add this to the documentation wiki too.


Samah(Posted 2012) [#6]
Monkey has an official naming convention? I've just always used my own.

Constants: ALL_CAPS_WITH_UNDERSCORES
Methods, functions, classes, properties, keywords: PascalCase
Fields, globals, local variables: camelCase
Packages/module names: alllowercaseregardlessofwordboundaries

Properties are (if possible) the same name as the field (if it's an accessor), but PascalCase instead of camelCase.

Field blah:Int

Method Blah:Int() Property
  Return blah
End

Method Blah:Void(blah:Int) Property
  Self.blah = blah
End



therevills(Posted 2012) [#7]
Monkey has an official naming convention?


Yep!

http://blitz-wiki.appspot.com/Language_reference#identifiers


Monkey naming conventions

The standard Monkey modules use a simple naming convention:

All-caps case (eg: 'ALLCAPS' ): Constants.

Pascal case (eg: 'PascalCase' ): Globals, functions, class, methods, properties.

Camel case (eg: 'camelCase' ): Fields, locals and function parameters.

You are of course free to use your own convention, but for the sake of consistency it is recommended that this convention be used for the public interface of any modules you create intended for use by the Monkey community.




Paul - Taiphoz(Posted 2012) [#8]
I already knew about the class and import, I name all my class's cMyclass with the small c Identifying the handle as a class.

As for standards mine is all over the place, I generally use PascalCase but I often just switch to lowercase it's something I struggle with all the time being Dyslexic, and something I have to remind myself to do, my Important variables and menthods and functions are all Pascal case, my locals tend to be all lower case along with my fields.

But some times I slip up forget and a capital slips in some where, I tried slipping an underscore at the start of all fields but that got old real fast and I never did it again.

As I plan to release this module for others to use as well, I will make an extra effort to keep the standard throughout, otherwise lol some of you might get annoyed with it real fast.

Would be real nice if the IDE had an option to track this and enforce it, would help people like me out who often simply dont see the difference between playerX and playerx .