Changes between Version 1 and Version 2 of GUI_-_Coding_Conventions
- Timestamp:
- Apr 30, 2014, 8:01:28 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GUI_-_Coding_Conventions
v1 v2 1 1 = Overview = 2 2 3 Where possible, we should endeavour to share [wiki:Coding_Conventions Coding Conventions] with the engine programmers.3 Where possible, share the engine [wiki:Coding_Conventions Coding Conventions]. 4 4 5 5 = Naming Conventions = 6 6 7 Use only '''alphanumerics''' (A..Z, a..z, 0-9) and '''underscores''' (_) for object names and parameters. Various special characters are reserved for use as delimiters and markers (particularly semicolons) , so it's best not to use anything else.7 Use only '''alphanumerics''' (A..Z, a..z, 0-9) and '''underscores''' (_) for object names and parameters. Various special characters are reserved for use as delimiters and markers (particularly semicolons). 8 8 9 Technically, the hyphen or dash (-) can be used interchangeably with hyphens, but you'll need to reference the string in a different way :9 Technically, the hyphen or dash (-) can be used interchangeably with hyphens, but you'll need to reference the string in a different way. For example: 10 10 11 11 {{{ 12 12 object.cell_id 13 13 }}} 14 14 … … 16 16 17 17 {{{ 18 18 object["cell-id"] 19 19 }}} 20 21 For consistency, though, it's best to just stick to alphanumerics and underscores.22 20 23 21 = Variable Casing = 24 22 25 Functions, variables, and objects written in JavaScript should be created using ''camelCase capitalisation'' (the first word is in lower 23 Functions, variables, and objects written in JavaScript should be created using ''camelCase capitalisation'' (the first word is in lowercase, and any additional words in title-case eg: '''setModifiedFlag()'''). 26 24 27 For inherited components, however -- "core XML", exposed engine functions and built-in JS commands -- their own casing will of course need to be maintained in order for the commands to be recognised. These tend to be camelCase or lowercase for the most part. Endeavouring to use camelCase where possible should provide a reasonable middle ground.25 For XML names, use all title-casing. (Eg: '''MyExampleName''') 28 26 29 27 Example of conventional scripted casing: 30 28 31 29 {{{ 32 <object name="exampleObject" 33 style="myStyle" 34 > 30 <object name="ExampleObject" style="ModernStyle"> 31 <action on="Press"> 32 guiHide(this.name); 33 </action> 34 </object> 35 }}} 36 37 = XML Formatting = 38 Some JavaScript operators (like &&) interfere with the XML parser and need to be surrounded with <![CDATA[''someCode'']]>. The above example with CDATA looks like: 39 {{{ 40 <object name="ExampleObject" style="ModernStyle"> 35 41 <action on="Press"><![CDATA[ 36 guiHide 42 guiHide(this.name); 37 43 ]]></action> 38 44 </object> 39 45 }}} 40 41 = Formatting =42 43 * Use the "Good Bracketing" specified in [wiki:Coding_Conventions Coding Conventions] ({ } are horizontally aligned).44 * Use meaningful comments and variable names.