Skip to content

SpecificationIII · Types and values

3.15

Checking levels

The engine checks everything it can before running; whatever depends on concrete values, such as dividing by zero, it checks when running.

Markdown version

3.15.1 How it works

There are two moments to discover a problem:

  • Before running (static checking): the shape of the program, that names exist and that types fit. If something fails here, the program does not run.
  • When running (dynamic checking): whatever depends on the real value at that moment, such as dividing by zero, going outside an array or reading a variable without a value.
Figure 3.15-1.What is checked at each moment. The earlier an error is found, the cheaper it is to fix.

Two columns. Before running, shape, names, types and called subroutines are checked. When running, division by zero, indices, variables without a value and overflow are checked.

This program is correct for the analysis, because dividing two integers makes sense. But when running, the divisor is zero:

ProgramCorrect when analysed, fails when run

Algorithm DividirCero
  Define edad As Integer <- 10;
  Define divisor As Integer <- 0;
  Write edad Div divisor;
EndAlgorithm

Diagnostics

  • divisionByZero · error · 4:14 · Division by zero

The program finishes with an error.

On the other hand, storing a text in an integer variable is found without running anything:

ProgramAn error seen beforehand

Algorithm TipoMal
  Define edad As Integer <- "diez";
EndAlgorithm

Diagnostics

  • incompatibleTypesInAssignment · error · 2:3 · Incompatible types in assignment: cannot assign string to integer

The program finishes with an error.

3.15.2 A failure is never silent

When a dynamic check fails, the program does not go on with an invented value: it stops at that statement with a diagnostic that says what happened and where. Expected failures from the outside world, such as a file that does not exist, do not stop the program: they come back as a Result so the program decides.

In short

  • Before running, shape, names and types are checked.
  • When running, concrete values are checked.
  • A runtime failure stops the program with a precise diagnostic.
  • Expected failures from outside arrive as a Result.