Changes between Version 1 and Version 2 of GUI_-_Coding_Conventions


Ignore:
Timestamp:
Apr 30, 2014, 8:01:28 AM (10 years ago)
Author:
Josh
Comment:

Remove some duplication and increase readability.

Legend:

Unmodified
Added
Removed
Modified
  • GUI_-_Coding_Conventions

    v1 v2  
    11= Overview =
    22
    3 Where possible, we should endeavour to share [wiki:Coding_Conventions Coding Conventions] with the engine programmers.
     3Where possible, share the engine [wiki:Coding_Conventions Coding Conventions].
    44
    55= Naming Conventions =
    66
    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.
     7Use 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).
    88
    9 Technically, the hyphen or dash (-) can be used interchangeably with hyphens, but you'll need to reference the string in a different way:
     9Technically, the hyphen or dash (-) can be used interchangeably with hyphens, but you'll need to reference the string in a different way. For example:
    1010
    1111{{{
    12   object.cell_id
     12object.cell_id
    1313}}}
    1414
     
    1616
    1717{{{
    18   object["cell-id"]
     18object["cell-id"]
    1919}}}
    20 
    21 For consistency, though, it's best to just stick to alphanumerics and underscores.
    2220
    2321= Variable Casing =
    2422
    25 Functions, variables, and objects written in JavaScript should be created using ''camelCase capitalisation'' (the first word is in lower case, and any additional words in title-case eg: '''setModifiedFlag()''').
     23Functions, 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()''').
    2624
    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.
     25For XML names, use all title-casing. (Eg: '''MyExampleName''')
    2826
    2927Example of conventional scripted casing:
    3028
    3129{{{
    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 =
     38Some 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">
    3541          <action on="Press"><![CDATA[
    36                  guiHide (this.name);
     42                 guiHide(this.name);
    3743          ]]></action>
    3844  </object>
    3945}}}
    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.