Skip to content

Commit bc40d9f

Browse files
authored
Merge pull request livecode#4587 from peter-b/bugfix-18086-tweaks
[Bug 18086] Further refinements to LCB style guide
2 parents 0e8916a + 9240d4d commit bc40d9f

1 file changed

Lines changed: 58 additions & 31 deletions

File tree

docs/guides/LiveCode Builder Style Guide.md

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ For `Boolean` variables, please try to use "yes or no" names. For example:
7878

7979
### Naming handlers
8080

81-
Give handlers `TitleCase` names.
81+
Give handlers `camelCase` names.
8282

8383
Use verbs to name your handlers. For example,
8484

85-
handler RotateShape(inout xShape, in pAngleInDegrees)
85+
handler rotateShape(inout xShape, in pAngleInDegrees)
8686
-- ...
8787
end handler
8888

@@ -96,14 +96,43 @@ To distinguish from handlers, use nouns to name your types. For example,
9696

9797
## Documenting the source code
9898

99-
You should add in-line documentation to `syntax` and `handler`
100-
definitions in LiveCode Builder source code. It is particularly
101-
important to add documentation to all syntax and to any public
102-
handlers that aren't primarily accessed using syntax.
103-
104-
In-line documentation for a handler or syntax definition is extracted from a
99+
In-line documentation for a definition is extracted from a
105100
`/** */` comment block immediately before the start of the definition.
106101

102+
Always add a top-level documentation block at the start of the LCB
103+
file describing your widget, library or module. In addition, add
104+
in-line documentation to all of the following:
105+
106+
- `syntax` definitions
107+
- `property` definitions
108+
- `public handler` definitions in libraries and modules
109+
- `public variable` definitions in modules
110+
111+
It is particularly important to add documentation to all syntax and to
112+
any public handlers that aren't primarily accessed using syntax.
113+
114+
Additionally, add documentation for all messages that are posted by a
115+
widget. The documentation for each message must be placed in the
116+
top-level documentation block for the widget. For example:
117+
118+
/*
119+
The navigation bar widget is intended for use in mobile apps for
120+
switching between cards, although there are many other possible
121+
uses.
122+
123+
...
124+
125+
Name: hiliteChanged
126+
Type: message
127+
Syntax: on hiliteChanged
128+
Summary: Sent when a navigation item is selected
129+
130+
...
131+
*/
132+
widget com.livecode.widget.navbar
133+
-- ..
134+
end widget
135+
107136
Please refer to the [Extending LiveCode](Extending LiveCode.md) guide for full
108137
details of the syntax of in-line documentation comments, including examples.
109138

@@ -115,7 +144,7 @@ want to create three tabs labelled "Things", "Stuff", and "Misc":
115144

116145
constant kTabNames is ["Things", "Stuff", "Misc"]
117146

118-
handler CreateTabs()
147+
handler createTabs()
119148
variable tName
120149
repeat for each element tName in kTabNames
121150
-- Create the tab
@@ -140,7 +169,7 @@ For example:
140169
module org.example.indent
141170

142171
-- Example handler
143-
handler Fizzbuzz(in pIsFizz)
172+
handler fizzBuzz(in pIsFizz)
144173
if pIsFizz then
145174
return "Fizz"
146175
else
@@ -166,7 +195,7 @@ example:
166195
When breaking a handler definition or handler type definition, break
167196
long lines at commas:
168197

169-
handler ProcessStringAndArray(in pStringArg as String, \
198+
handler processStringAndArray(in pStringArg as String, \
170199
in pArrayArg as Array) returns Boolean
171200

172201
### Handler declarations, definitions and calls
@@ -175,21 +204,21 @@ In handler definitions and handler type definitions, don't insert
175204
whitespace between the handler name and the parameter list. For
176205
example:
177206

178-
handler type Fizz() -- Good
179-
handler type Buzz () -- Bad
207+
handler type Fizzer() -- Good
208+
handler type Buzzer () -- Bad
180209

181210
In handler parameter lists, please add a space between each parameter. For
182211
example:
183212

184-
handler FormatAsString(in pValue, out rFormat) -- Good
185-
handler IsEqualTo(in pLeft,in pRight) -- Bad
213+
handler formatAsString(in pValue, out rFormat) -- Good
214+
handler isEqualTo(in pLeft,in pRight) -- Bad
186215

187216
Please observe the same formatting in handler calls. For example:
188217

189218
variable tFormatted
190219
variable tIsEqual
191-
FormatAsString(3.1415, tFormatted) -- Good
192-
IsEqualTo (tFormatted,"3.1415") into tIsEqual -- Bad
220+
formatAsString(3.1415, tFormatted) -- Good
221+
isEqualTo (tFormatted,"3.1415") into tIsEqual -- Bad
193222

194223
### List and array literals
195224

@@ -198,7 +227,7 @@ after the comma. For array literals, also insert space between key
198227
and value, after the colon. For example:
199228

200229
constant kPowersOfTwo is [1, 2, 4, 8]
201-
constant kBordeWidths is {"top": 0, "bottom": 0, "left": 1, "right": 2}
230+
constant kBorderWidths is {"top": 0, "bottom": 0, "left": 1, "right": 2}
202231

203232
## Widget-specific guidelines
204233

@@ -211,27 +240,25 @@ properties with similar semantics.
211240

212241
### Writing load handlers
213242

214-
When writing an `OnLoad()` handler to initialise a widget from
243+
When writing an `onLoad()` handler to initialise a widget from
215244
serialised state:
216245

217246
- Always call property setters to update the widget state. Do not set
218247
instance variables directly.
219-
220248
- Always check that the property array contains each key rather than
221249
accessing it unilaterally.
222-
223250
- If keys are absent from the property array, do not set them to
224-
default values. Rely on the `OnCreate()` handler to have already
251+
default values. Rely on the `onCreate()` handler to have already
225252
done that.
226253

227254
Example:
228255

229-
public handler OnLoad(in pProperties)
256+
public handler onLoad(in pProperties)
230257
if "showBorder" is among the keys of pProperties then
231-
SetShowBorder(pProperties["showBorder"])
258+
setShowBorder(pProperties["showBorder"])
232259
end if
233260
if "opaque" is among the keys of pProperties then
234-
SetShowBackground(pProperties["opaque"])
261+
setShowBackground(pProperties["opaque"])
235262
end if
236263
end handler
237264

@@ -293,14 +320,14 @@ For example, to shadow the `borderColor` host control property:
293320

294321
Always implement:
295322

296-
- `OnCreate()`
297-
- `OnSave()`
298-
- `OnLoad()`
299-
- `OnPaint()`
323+
- `onCreate()`
324+
- `onSave()`
325+
- `onLoad()`
326+
- `onPaint()`
300327

301328
You should _usually_ implement:
302329

303-
- `OnGeometryChanged()`: if you have any non-trivial recomputation
330+
- `onGeometryChanged()`: if you have any non-trivial recomputation
304331
required to handle resizing
305-
- `OnMouseDown()`/`OnMouseUp()`/`OnMouseMove()`: always `post` these to
332+
- `onMouseDown()`/`onMouseUp()`/`onMouseMove()`: always `post` these to
306333
script in order to behave like a classic control

0 commit comments

Comments
 (0)