Logo BCDDLogo CSC
BCDDBehavioural Contract-Driven Design
version 1.0-beta
ITEN

Chapter 29 — The complete procedure, from start to finish

This chapter writes the staircase light CSC from the beginning, using the four commands of bcdd in sequence: new creates the skeleton, check checks the form, refine submits the CSC to a language model and ratify records the approval. Each step refers back to the chapter that describes it. At the end the chapter indicates what the program does not do.

The skeleton

$ bcdd new UsoLuce
created UsoLuce.csc

The file created contains the header with STATUS HYPOTHESIS, a purpose to be filled in, the forms suggested in the comments and END (chapter 7). The skeleton already passes the check:

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 17 (recognised 4, comments 10, blank 3, unrecognised 0)
blocks: 1
  line 4: CSC UsoLuce VERSION 0.1, STATUS HYPOTHESIS

1. ERRORS: 0
…
outcome: no errors

The outcome attests that the file is written correctly, not that it contains a description: the purpose is still “to be filled in”.

The first draft, by hand

The CSC is written by hand, entirely in words (chapters 2-4): the purpose, the input and output events, the states observable at the boundary, the guarantees and the assumptions. The comments of the skeleton are removed.

-- The staircase light, as seen by the person on the stairs.

CSC UsoLuce VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The person on the stairs presses a button and has light to go up or down"

  EVENT IN   premuto
  EVENT OUT  avviso
  STATE      accesa : Boolean INITIAL false

  GUARANTEE g1: VERBAL "When someone presses the button, the light switches on"
                VERIFY BY JUDGEMENT "a person who presses the button and watches"
  GUARANTEE g2: VERBAL "The light switches off by itself after a while"
                VERIFY BY JUDGEMENT "a person with a watch"
  GUARANTEE g3: VERBAL "Shortly before switching off, the light gives a warning to the person on the stairs"
                VERIFY BY JUDGEMENT "a person on the stairs who waits for the light to switch off"
  ASSUME    a1: VERBAL "Whoever presses the button holds it down for at least a tenth of a second"
                VERIFY BY JUDGEMENT "a person who observes how the button is pressed"
END

The check

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 19 (recognised 15, comments 1, blank 3, unrecognised 0)
blocks: 1
  line 3: CSC UsoLuce VERSION 0.1, STATUS HYPOTHESIS

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 4
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 11: GUARANTEE g1 verbal
  line 13: GUARANTEE g2 verbal
  line 15: GUARANTEE g3 verbal
  line 17: ASSUME a1 verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 4
  line 11: GUARANTEE g1
  line 13: GUARANTEE g2
  line 15: GUARANTEE g3
  line 17: ASSUME a1

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

outcome: no errors

The file is written correctly and the four contractual lines are pending approval. Two guarantees remain vague: g2 does not specify after how long the light switches off; g3 does not specify how long before the switch-off the warning arrives.

The questions of the language model

With bcdd refine the language model asks questions on the vague points and proposes details (chapter 8). The initial lines, which show the check of the file and the call to the model, are omitted; the questions and the proposals vary from one run to another.

$ bcdd refine UsoLuce.csc
…
QUESTION 1 of 2
  How long after the last press must the light switch off, and with what tolerance?
  1) 60 seconds, with a tolerance of 5 seconds
  2) 90 seconds, with a tolerance of 5 seconds
  3) 3 minutes, with a tolerance of 10 seconds
answer (1 to 3, or write your own; press Enter alone to skip): 2
  choice 2: 90 seconds, with a tolerance of 5 seconds

QUESTION 2 of 2
  How long before switch-off does the warning arrive?
  1) 5 seconds before
  2) 10 seconds before
answer (1 to 2, or write your own; press Enter alone to skip): 1
  choice 1: 5 seconds before
…
PROPOSAL 1 of 3, details g2 (line 13)
  GUARANTEE g2a DETAILS g2 STATUS HYPOTHESIS: VERBAL "The light switches off 90 s after the last press, with a tolerance of 5 s"
                                              VERIFY BY JUDGEMENT "a person who measures with a stopwatch the time between the last press and switch-off"
accept? y = yes, n = no, q = quit (discards the rest): y

PROPOSAL 2 of 3, details g2 (line 13)
  GUARANTEE g2b DETAILS g2 STATUS HYPOTHESIS: VERBAL "A press while the light is on restarts the 90 s from the beginning"
                                              VERIFY BY JUDGEMENT "a person who presses the button again while the light is on and measures with a stopwatch the time until switch-off"
accept? y = yes, n = no, q = quit (discards the rest): y

PROPOSAL 3 of 3, details g3 (line 15)
  GUARANTEE g3a DETAILS g3 STATUS HYPOTHESIS: VERBAL "The warning arrives between 15 and 5 s before switch-off"
                                              VERIFY BY JUDGEMENT "a person on the stairs with a stopwatch"
accept? y = yes, n = no, q = quit (discards the rest): n

summary: accepted 2, discarded by you 1, discarded by the check 0
write 2 proposals (4 lines) in UsoLuce.csc and 2 answers in UsoLuce.csc.dialogo? y = yes, n = no: y
written UsoLuce.csc: 2 proposals (4 lines)
written UsoLuce.csc.dialogo: 2 answers

The third proposal does not correspond to the answer given, 5 seconds before, and is discarded. The proposals are accepted or discarded at the judgement of whoever writes the CSC: the model proposes, and only what is accepted and confirmed enters the file. Every line written in this way remains pending approval.

Corrections by hand and the scenarios

The detail of g3 is written by hand, like any line. The scenarios are also added (chapter 9), and they must be written before the approval: a scenario is not added to an approved CSC. The last lines of the file become:

  GUARANTEE g3a DETAILS g3: VERBAL "The warning arrives 5 s before switch-off, with a tolerance of 1 s"
                            VERIFY BY JUDGEMENT "a person on the stairs who measures with a stopwatch the time between the warning and switch-off"
  ASSUME    a1: VERBAL "Whoever presses the button holds it down for at least a tenth of a second"
                VERIFY BY JUDGEMENT "a person who observes how the button is pressed"

  SCENARIO s1 EXPECT ADMITTED
    @0 s     premuto    accesa = true
    @85 s    avviso
    @90 s    accesa = false
  SCENARIO s2 EXPECT REJECTED
    @0 s     premuto    accesa = true
    @30 s    accesa = false
END

Scenario s1 must be admitted: the light switches off 90 seconds after the press, with the warning 5 seconds before. Scenario s2 must be rejected: the light switches off after 30 seconds, in contrast with g2a.

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 33 (recognised 28, comments 1, blank 4, unrecognised 0)
blocks: 1
  line 3: CSC UsoLuce VERSION 0.1, STATUS HYPOTHESIS

1. ERRORS: 0
…
4. PENDING APPROVAL, NOT CONTRACT: 7
  line 11: GUARANTEE g1
  line 13: GUARANTEE g2
  line 15: GUARANTEE g2a
  line 17: GUARANTEE g2b
  line 19: GUARANTEE g3
  line 21: GUARANTEE g3a
  line 23: ASSUME a1
…
outcome: no errors

The approval

The building manager examines the CSC and approves it with the decision D-1, noted in the register of decisions. bcdd ratify records the approval in the file (chapter 7):

$ bcdd ratify UsoLuce.csc --all D-1
approved with D-1 in CSC UsoLuce: 4 lines
  line 4: CSC UsoLuce
  line 15: GUARANTEE g2a
  line 17: GUARANTEE g2b
  line 21: GUARANTEE g3a
contract: 7

The command modifies four lines: the header and the three details. A detail does not follow the STATUS of the header (chapter 8), so each one is assigned its own, including g3a, which had none. The other contractual lines take that of the header. In the output of bcdd ratify the line number is that of the modified line: for the header it is the STATUS line (line 4), whereas the report of bcdd check indicates the CSC line (line 3). The final report confirms the approval:

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 33 (recognised 28, comments 1, blank 4, unrecognised 0)
blocks: 1
  line 3: CSC UsoLuce VERSION 0.1, STATUS RATIFIED BY D-1

1. ERRORS: 0
…
4. PENDING APPROVAL, NOT CONTRACT: 0
…
outcome: no errors

The CSC is now the contract between the building manager and whoever implements the light.

After the approval

Approved lines are not modified. A later modification, for example a different on-time, is written in a new version, to be approved again (chapter 10). When the system becomes more complex, the description is divided into several CSCs, one per boundary, and the entity is introduced (chapters 11-13). The guarantees that a program must be able to check are written as formulas (chapters 21-23).

What the program does not do

bcdd checks the form of files and writes to a file only when a command provides for it. In particular:

Summary