03: Label Convention
"Readible - Modular - Expandable code"
Applied Object-Based Programming relies on several simple labeling rules to imitate many OOP features such as Namespaces and Encapsulation. In this lesson you will learn how using a Label Convention will increase your programming productivity. Why you may ask? My answer is simple: by following these rules your code become structured and standardized. Others who know these rules will be able to quickly interpret and extend your code.
Labels are made up of the following words: Prefix, Object, BaseObject, Property, Purpose.
Prefix - Optional acronym for the project. It is used for all labels. Ideal for code libraries.
Object - Name of the Object
BaseObject - Name of an Base Object Pointer
Property - Name of an Object's Property
Purpose - A Verb or short phrase that describes the purpose/action of Object's Method or Construct.
The Rules
Below are the specifc rules for labeling an Object's Methods and Constructs.
Constants: All Caps. Each word separated with an underscore(_).
{PREFIX}_{OBJECT}_{BASEOBJECT}_{PURPOSE}
Example: Const MYGAME_PLAYER_MAXCOUNT%
Globals and Arrays: Capitalize the first letter of Object, BaseObject, Property, Purpose. Each word separated with an underscore(_).
{Prefix}_{Object}_{BaseObject}_{Property}_{Purpose}
Example: Global MyGame_Player_Active%
Example: Dim MyGame_PlayerID(MYGAME_PLAYER_MAXCOUNT%)Functions (Methods): Capitalize the first letter of Object, BaseObject, Property, Purpose. Only the Prefix is separated with an underscore(_).
{Prefix}_{Object}|{BaseObject}{Property}{Purpose}.{ReturnObject}
Example: Function MyGame_playerWeaponAmmunitionLoad(this.player)
Example: Function MyGame_playerWeaponAmmunitionLoadByPower(this.player)Function Parameters and Local Variables: All lower case. No underscore(_).
{prefix}{object}{methodparameter}
Example: Function MyGame_playerMovement(this.player, mygameplayerx#, mygameplayery#)
Object Pointer by ID: Capitalize the first letter of Object, BaseObject, Property, Purpose. Each word separated with an underscore(_). Uses Global Keyword and '[]'.
Global {prefix}{object}_ID.{ReturnObject}[Elements]
{Prefix}{Object}_ID[objectid]=instance
Example: Global MyGame_player_ID.player[MYGAME_PLAYER_MAXCOUNT%]
Pointer Assignment: MyGame_player_ID[this\id]=thisObject Key: 'ID' Suffix added to Field label.
Field ID%
Field {baseobject}ID%Example: Field playerWeaponProfileID%
Highly Recommended Reading: Writing Readable Code by Brent P. Newhall
Exercise: