_CodingConventions.xba 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="_CodingConventions" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
  4. REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
  5. REM === Full documentation is available on https://help.libreoffice.org/ ===
  6. REM =======================================================================================================================
  7. &apos;&apos;&apos;
  8. &apos; Conventions used in the coding of the *ScriptForge* library
  9. &apos; -----------------------------------------------------------
  10. &apos;&apos;&apos;
  11. &apos; Library and Modules
  12. &apos; ===================
  13. &apos; * Module names are all prefixed with &quot;SF_&quot;.
  14. &apos; * The *Option Explicit* statement is mandatory in every module.
  15. &apos; * The *Option Private Module* statement is recommended in internal modules.
  16. &apos; * A standard header presenting the module/class is mandatory
  17. &apos; * An end of file (eof) comment line is mandatory
  18. &apos; * Every module lists the constants that are related to it and documented as return values, arguments, etc.
  19. &apos; They are defined as *Global Const*.
  20. &apos; The scope of global constants being limited to one single library, their invocation from user scripts shall be qualified.
  21. &apos; * The Basic reserved words are *Proper-Cased*.
  22. &apos;&apos;&apos;
  23. &apos; Functions and Subroutines
  24. &apos; =========================
  25. &apos; * LibreOffice ignores the Private/Public attribute in Functions or Subs declarations.
  26. &apos; Nevertheless the attribute must be present.
  27. &apos; Rules to recognize their scope are:
  28. &apos; * Public + name starts with a letter
  29. &apos; The Sub/Function belongs to the official ScriptForge API.
  30. &apos; As such it may be called from any user script.
  31. &apos; * Public + name starts with an underscore &quot;_&quot;
  32. &apos; The Sub/Function may be called only from within the ScriptForge library.
  33. &apos; As such it MUST NOT be called from another library or from a user script,
  34. &apos; as there is no guarantee about the arguments, the semantic or even the existence of that piece of code in a later release.
  35. &apos; * Private - The Sub/Function name must start with an underscore &quot;_&quot;.
  36. &apos; The Sub/Function may be called only from the module in which it is located.
  37. &apos; * Functions and Subroutines belonging to the API (= &quot;standard&quot; functions/Subs) are defined in their module in alphabetical order.
  38. &apos; For class modules, all the properties precede the methods which precede the events.
  39. &apos; * Functions and Subroutines not belonging to the API are defined in their module in alphabetical order below the standard ones.
  40. &apos; * The return value of a function is always declared explicitly.
  41. &apos; * The parameters are always declared explicitly even if they&apos;re variants.
  42. &apos; * The Function and Sub declarations start at the 1st column of the line.
  43. &apos; * The End Function/Sub statement is followed by a comment reminding the name of the containing library.module and of the function or sub.
  44. &apos; If the Function/Sub is declared for the first time or modified in a release &gt; initial public release, the actual release number is mentioned as well.
  45. &apos;&apos;&apos;
  46. &apos; Variable declarations
  47. &apos; =====================
  48. &apos; * Variable names use only alpha characters, the underscore and digits (no accented characters).
  49. &apos; Exceptionally, names of private variables may be embraced with `[` and `]` if `Option Compatible` is present.
  50. &apos; * The Global, Dim and Const statements always start in the first column of the line.
  51. &apos; * The type (*Dim ... As ...*, *Function ... As ...*) is always declared explicitly, even if the type is Variant.
  52. &apos; * Variables are *Proper-Cased*. They are always preceded by a lower-case letter indicating their type.
  53. &apos; With next exception: variables i, j, k, l, m and n must be declared as integers or longs.
  54. &apos; &gt; b Boolean
  55. &apos; &gt; d Date
  56. &apos; &gt; v Variant
  57. &apos; &gt; o Object
  58. &apos; &gt; i Integer
  59. &apos; &gt; l Long
  60. &apos; &gt; s String
  61. &apos; Example:
  62. &apos; Dim sValue As String
  63. &apos; * Parameters are preceded by the letter *p* which itself precedes the single *typing letter*.
  64. &apos; In official methods, to match their published documentation, the *p* and the *typing letter* may be omitted. Like in:
  65. &apos; Private Function MyFunction(psValue As String) As Variant
  66. &apos; Public Function MyOfficialFunction(Value As String) As Variant
  67. &apos; * Global variables in the ScriptForge library are ALL preceded by an underscore &quot;_&quot; as NONE of them should be invoked from outside the library.
  68. &apos; * Constant values with a local scope are *Proper-Cased* and preceded by the letters *cst*.
  69. &apos; * Constants with a global scope are *UPPER-CASED*.
  70. &apos; Example:
  71. &apos; Global Const ACONSTANT = &quot;This is a global constant&quot;
  72. &apos; Function MyFunction(pocControl As Object, piValue) As Variant
  73. &apos; Dim iValue As Integer
  74. &apos; Const cstMyConstant = 3
  75. &apos;&apos;&apos;
  76. &apos; Indentation
  77. &apos; ===========
  78. &apos; Code shall be indented with TAB characters.
  79. &apos;&apos;&apos;
  80. &apos; Goto/Gosub
  81. &apos; ==========
  82. &apos; The *GoSub* … *Return* statement is forbidden.
  83. &apos; The *GoTo* statement is forbidden.
  84. &apos; However *GoTo* is highly recommended for *error* and *exception* handling.
  85. &apos;&apos;&apos;
  86. &apos; Comments (english only)
  87. &apos; ========
  88. &apos; * Every public routine should be documented with a python-like &quot;docstring&quot;:
  89. &apos; 1. Role of Sub/Function
  90. &apos; 2. List of arguments, mandatory/optional, role
  91. &apos; 3. Returned value(s) type and meaning
  92. &apos; 4. Examples when useful
  93. &apos; 5. Eventual specific exception codes
  94. &apos; * The &quot;docstring&quot; comments shall be marked by a triple (single) quote character at the beginning of the line
  95. &apos; * Meaningful variables shall be declared one per line. Comment on same line.
  96. &apos; * Comments about a code block should be left indented.
  97. &apos; If it concerns only the next line, no indent required (may also be put at the end of the line).
  98. &apos;&apos;&apos;
  99. </script:module>