Type / Class in-code name conventions / policy

Monkey Forums/Monkey Programming/Type / Class in-code name conventions / policy

Playniax(Posted 2011) [#1]
Hi guys,

In BlitzMax we used to put a T before a type e.g. TSprite

I know in monkey types are classes and seeing the examples from Monkey this is not common practice anymore to put for example CSprite but just Sprite.

How do you feel about this? Any sugestions?

Thanks!


GW_(Posted 2011) [#2]
I still use the 't' prefix. but it's all just a personal preference


Playniax(Posted 2011) [#3]
Yep, but when writing a module or framework it's nice to know what people prefer.


Xaron(Posted 2011) [#4]
I would just prefer Sprite.


okee(Posted 2011) [#5]
I always used the T, what's the convention for classes in other languages ?


Difference(Posted 2011) [#6]
I think one of the ideas with making Monkey case sensitive, was to allow you to do away with the t prefix.

tMyclass could now be Myclass (or MyClass ?) and then variables can start with small letters.


therevills(Posted 2011) [#7]
In Java the class convention is the name with a captial first letter, in the example for a sprite class, it would be just Sprite. For a enemy sprite class it would be EnemySprite.

The issue with using this in Monkey, is that the internal commands(methods) use this convention for methods, so you wont know what is a class or a method by looking at the call.

Here is a link for the Java conventions:
http://www.oracle.com/technetwork/java/codeconventions-135099.html#367


Canardian(Posted 2011) [#8]
I use capital first letter for class names and all small for variable names. If the variable name is very long, then I add an underscore also, but with classes variable names don't get very long, so underscores are never needed.


therevills(Posted 2011) [#9]
This is what I think I will use with Monkey:

Class:
Class Sprite


Variables:
Field playerBat:Sprite


Methods / functions:
Method collisions:Void()

Function rectsOverlap:Int(x0:Float, y0:Float, w0:Float, h0:Float, x2:Float, y2:Float, w2:Float, h2:Float)


Consts:
Const MAX_TILES% = 32



Canardian(Posted 2011) [#10]
Small first letter and caps in the middle are the worst way, it looks really annoying :)


MikeHart(Posted 2011) [#11]
Imho it is all personal taste. Use what fits the best and if you create something for other people, use the methods of how the official modules use their naming conventions.


Canardian(Posted 2011) [#12]
In the official modules variables are all small, and class names, methods and functions are first character per word capital. That's the best style!


Richard Betson(Posted 2011) [#13]
^Yup that's the convention we've been using.


impixi(Posted 2011) [#14]
From the docs (Monkey Language Reference section):


Monkey naming convention

The standard Monkey modules use a simple naming convention:

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

Constants


Pascal case (eg: 'PascalCase' ):

Classes
Globals
Functions, methods and 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.





Canardian(Posted 2011) [#15]
Camel case should be forbidden by Texas laws!


Perturbatio(Posted 2011) [#16]

Small first letter and caps in the middle are the worst way, it looks really annoying :)



iHaveNoProblem withThatPersonally, thisontheotherhand isfarworse butalltoooftenseen


ziggy(Posted 2011) [#17]
lowercase methods will make it impossible to diferenciate a property method from a regular field :D I would case them.


Samah(Posted 2011) [#18]
Given that I code Java every day, I think I'll be sticking with this:

Constants:
UPPER_CASE_WITH_UNDERSCORES

Classes and keywords:
TitleCase

Fields, methods, functions, global and local variables:
camelCase

The only exception to method names is New since it is also a keyword.

The main point of naming conventions is so that you can (theoretically) look at an identifier and have a pretty good idea of what it is.


therevills(Posted 2011) [#19]
make it impossible to diferenciate a property method from a regular field


Thats why when calling a method you should use the brackets:

thisIsAField

thisIsAMethod()



Tommo(Posted 2011) [#20]
I like lowercase for keywords, uppercase for constants, pascalcase for class and camelcase for all the rest.


FlameDuck(Posted 2011) [#21]
I always used the T, what's the convention for classes in other languages ?
Depends on the language. In Monkey the convention is much like Java (see: Monkey Language Reference -> Identifiers -> Monkey naming convention), that is no Hungarian notation. Personally I'm in favour of the change as it can really get out of hand some times. Besides any typesafe language doesn't really need it IMHO.


Tibit(Posted 2011) [#22]
Playniax, I'm also building a Framework and being consistent is imo the most important thing. Here is my code standard, feel free to use :)

Code standards can be a good way to improve your code quality, and since I in no way suggest this is the perfect way to code in Monkey, it is just one suggested way, I'm open for feedback!

Website version
Word Version

* One thing I have changed in it, is that private variables can be lowerCased if they are 100% private and are not used in inheritance.

EDIT - How to make links, appear like links?


Xaron(Posted 2011) [#23]
Links: (a http://blah)Linkdescription(/a)

Replace () with []


Playniax(Posted 2011) [#24]
Thanks for the feedback guys! I think I will go for about the same style as the Monkey modules but I dislike the camelCase (sorry Mark:)

In our Ignition framework I start every function and type with an 'i' e.g. iCLS or iDrawImage or iTSprite for a type, just to make it clear that it's a framework part.

I think at the end doesn't matter and like Tibit said, being consistent is the most important.

I'm going to think out it.


Xaron(Posted 2011) [#25]
I like the camelCase. It makes sense. We use it in our company as well (all this Java type stuff but with C++)