Skip to content

Commit 6ee16c6

Browse files
create_checker.md: Expand explanations (#465)
* create_checker.md: Expand explanations Signed-off-by: David A. Wheeler <[email protected]> * Fix internal named anchor values Signed-off-by: David A. Wheeler <[email protected]> --------- Signed-off-by: David A. Wheeler <[email protected]>
1 parent a1248e6 commit 6ee16c6

File tree

1 file changed

+57
-23
lines changed

1 file changed

+57
-23
lines changed

docs/labs/create_checker.md

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,49 @@ These are the instructions for how to create labs with `checker.js`,
66

77
The `checker.js` system
88
represents each lab exercise in an HTML file.
9-
You define a pattern that the correct answer must match
10-
using regular expressions (as well as a example of an expected answer).
9+
You define text explaining the lab exercise,
10+
a form allowing the learner to enter their answer,
11+
pattern(s) that the correct answer(s) must match,
12+
and an example of an expected answer.
13+
14+
Everything runs in the user's browser - no installation is needed.
1115
This system does *not* run arbitrary code written by the user.
1216
You can also provide patterns for various hints.
1317

18+
There are three basic tasks, which can be done by different people:
19+
20+
1. Identifying the next lab to do.
21+
See the [README](./README.md) for the list of labs.
22+
2. [Creating the lab instructions and correct answer](#creating-the-lab-instructions-and-correct-answer).
23+
This is done by a subject matter expert. See below.
24+
3. [Creating the lab HTML file](#creating-the-lab-html-file).
25+
Much of the text below focuses on implementing this part.
26+
You'd typically start with an existing lab, like
27+
[input1.html](input1.html), and modify it for your situation.
28+
See David A. Wheeler who can help you get started.
29+
30+
The text below discusses these in more detail. You can also see our
31+
[potential future directions](#potential-future-directions).
32+
33+
## Creating the lab instructions and correct answer
34+
35+
We strongly urge you to first work out the basic lab and what
36+
a *correct* answer would look like. Others can help you create the pattern
37+
that describes a correct answer.
38+
39+
First consult the [section's text in the fundamentals course](more ~/projects/secure-sw-dev-fundamentals/secure_software_development_fundamentals.md).
40+
It's probably best to then create some simple program that
41+
demonstrates it, along with text that explains the task.
42+
43+
Remember that we're assuming that learners know how to program, but we
44+
do *not* assume they know any particular programming language.
45+
See [input1.html](input1.html),
46+
[input2.html](input2.html), and
47+
[csp1.html](csp1.html) for examples of how to do this.
48+
49+
## Creating the lab HTML file
50+
51+
Each lab is captured in its own HTML file.
1452
The HTML file of a given lab is expected to:
1553

1654
* Describe the exercise (in HTML text)
@@ -24,11 +62,7 @@ The HTML file of a given lab is expected to:
2462

2563
The system is implemented by the client-side JavaScript file `checker.js`.
2664

27-
## TL;DR
28-
29-
We strongly urge you to first work out the basic lab and what
30-
a *correct* answer would look like. Others can help you create the pattern
31-
that describes a correct answer.
65+
### TL;DR
3266

3367
An easy way implement a lab is to copy
3468
[input1.html](input1.html) and modify it for your situation.
@@ -49,7 +83,7 @@ We suggest including the buttons (Hint, Reset, and Give up)
4983
as shown in the examples.
5084
The code will automatically set up the buttons if they are present.
5185

52-
## Quick aside: script tag requirements
86+
### Quick aside: script tag requirements
5387

5488
Data about the lab is embedded in the HTML in a
5589
`script` tag. Embedding this data simplifies lab maintenance,
@@ -69,7 +103,7 @@ Basically, the text embedded in the `script` sections must
69103
If you *need* to include these text sequences inside the `script` region,
70104
you can typically you can replace `<` with `\x3C` to resolve it.
71105

72-
## Basic lab inputs
106+
### Basic lab inputs
73107

74108
The basic inputs are:
75109

@@ -83,12 +117,12 @@ in order (0, 1, 2, ...).
83117
The number of attempt fields, expected fields, and correct fields
84118
much match.
85119

86-
## Expressing correct answer patterns
120+
### Expressing correct answer patterns
87121

88122
Correct answer patterns are expressed using a preprocessed form of
89123
[JavaScript regular expression (regex) patterns](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions).
90124

91-
### Quick introduction to regular expressions (regexes)
125+
#### Quick introduction to regular expressions (regexes)
92126

93127
Regular expressions are a widely-used notation to
94128
indicate patterns.
@@ -106,7 +140,7 @@ the many different forms that are all correct. E.g.:
106140
* Pattern `9_?999` matches `9`, an optional underscore
107141
(<tt>&#95;</tt>) because the `?` makes it optional, then `999`.
108142

109-
### How we make regexes readable
143+
#### How we make regexes readable
110144

111145
Regexes are capable and widely used,
112146
but straightforward regex use for this problem
@@ -176,7 +210,7 @@ defining the lookahead patterns for all required specific answers.
176210
If you need that kind of order flexibility for longer lists, that is the
177211
best approach I've found.
178212

179-
## Expressing JavaScript code patterns
213+
### Expressing JavaScript code patterns
180214

181215
If you're defining a pattern to match an answer that is a
182216
snippet of JavaScript code, here are some tips:
@@ -202,7 +236,7 @@ It's impractical to match all possibilities, e.g., <tt>1</tt> can be
202236
written as <tt>(5-4)</tt>, but that would be an absurd thing for a
203237
student to do.
204238

205-
## Example pattern
239+
### Example pattern
206240

207241
Here's an example pattern for matching a correct answer:
208242

@@ -255,7 +289,7 @@ Here's an explanation of this pattern:
255289
By ending the last pattern with `\s*` we make it clear that
256290
trailing whitespace is allowed at the end.
257291

258-
## Other info
292+
### Other info
259293

260294
The id `info` can provide other optional information.
261295
If present, it must be a YAML object.
@@ -287,7 +321,7 @@ The `info` object also has other fields:
287321
some data that may help you debug problems.
288322
* `hints`: If present, this is an array of hints.
289323

290-
## Hints
324+
### Hints
291325

292326
Hints are expressed in the info `hints` field.
293327
This field must be an array
@@ -298,7 +332,7 @@ Each hint object describes a hint, and they are checked in the order given
298332
If you use JSON format,
299333
each hint object begins with `{`, has a set of fields, and ends with `}`.
300334

301-
### Format for a hint
335+
#### Format for a hint
302336

303337
Every hint object must have a `text` field to be displayed as the hint.
304338
A hint object can have a `present` field (a pattern that must be present
@@ -325,7 +359,7 @@ an array of examples (each example is an array of Strings).
325359
On load the system will verify that each example will report the
326360
maatching hint (this helps ensure that the hint order is sensible).
327361

328-
### Examples of hints
362+
#### Examples of hints
329363

330364
Here are examples of hints:
331365

@@ -355,7 +389,7 @@ the hint.
355389
The second hint triggers when the user attempt *contains* the given
356390
pattern (note the term `present`).
357391

358-
## Notes on YAML
392+
### Notes on YAML
359393

360394
The info section supports
361395
[YAML format version 1.2](https://yaml.org/spec/1.2.2/).
@@ -474,7 +508,7 @@ You can use
474508
[convert yaml to json](https://onlineyamltools.com/convert-yaml-to-json)
475509
to interactively experiment with YAML.
476510

477-
## Preventing problems
511+
### Preventing problems
478512

479513
As always, it's best to try to
480514
make smaller changes, test them, and once they work
@@ -488,7 +522,7 @@ Remember, hints are checked in order - it's possible to create a hint
488522
that won't trigger because something earlier would always match.
489523
These tests are automatically checked every time the page is (re)loaded.
490524

491-
## Debugging
525+
### Debugging
492526

493527
Sadly, sometimes things don't work; here are some debugging tips for labs.
494528

@@ -514,7 +548,7 @@ This will display information, particularly on its inputs.
514548
This can help you track down a problems if you think your
515549
inputs are being interpreted in a way different than you expect.
516550

517-
## Additional settings for natural languages other than English
551+
### Additional settings for natural languages other than English
518552

519553
This tool should work fine with languages other than English.
520554
We expect that there will be a different HTML page for each
@@ -524,7 +558,7 @@ lab and each different natural language.
524558
For each button you should set the `title` attribute for the
525559
given language.
526560

527-
## Advanced use: Select preprocessing commands (e.g., for other languages)
561+
### Advanced use: Select preprocessing commands (e.g., for other languages)
528562

529563
For most programming languages the default regex preprocessing
530564
should be fine. However, the *defaults* are *not* a

0 commit comments

Comments
 (0)