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.
Below are the specifc rules for labeling an Object's Methods and Constructs.
Constants: All Caps. Each word separated with an underscore(_).
Example: Const MYGAME_PLAYER_MAXCOUNT%
Globals and Arrays: Capitalize the first letter of Object, BaseObject, Property, Purpose. Each word separated with an underscore(_).
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(_).
Example: Function MyGame_playerWeaponAmmunitionLoad(this.player)
Example: Function MyGame_playerWeaponAmmunitionLoadByPower(this.player)
Function Parameters and Local Variables: All lower case. No underscore(_).
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 ''.
Example: Global MyGame_player_ID.player[MYGAME_PLAYER_MAXCOUNT%]
Pointer Assignment: MyGame_player_ID[this\id]=this
Object Key: 'ID' Suffix added to Field label.
Example: Field playerWeaponProfileID%
Highly Recommended Reading: Writing Readable Code by Brent P. Newhall
Email-in this Exercise for Grade!