Dialect "name"

Parameters

name - the dialect for this file, as a quoted lower-case literal
"classic": traditional Blitz3D syntax; variables may appear without being declared
"secure": classic syntax, but a variable read before it exists is reported
"modern": secure checking plus colon type annotations and period member access

Description

Chooses the source syntax and variable checking rules for the file it appears in.

Dialect is a compiler directive rather than a command - nothing happens at runtime. It must be the very first statement in the file, with only blank lines and comments allowed above it, and it may appear only once.

"classic" is Blitz3D as it always was. A name that has never been declared springs into existence the moment you use it, which is quick to write and forgiving of typos in exactly the way that costs you an evening: misspell health as heatlh in one place and you get a second variable sitting quietly at zero.

"secure" keeps every bit of classic syntax and adds the check that catches that. Using a variable in an expression before it exists is reported at compile time; assigning to a new name still introduces it, so existing code usually needs no more than a few Local and Global lines to build cleanly.

"modern" adds syntax on top of secure checking: colon type annotations (Local counter:Counter) and period member access (counter.value) in place of the classic backslash. It is the most explicit of the three and the easiest to read back months later.

The setting belongs to one file only. Each file pulled in with Include chooses its own dialect, and none is inherited, so you can modernise a project a file at a time instead of all at once. A file with no Dialect line follows the compiler's current language mode.

Dialect is not the same thing as the Original and Extended modes in the IDE. Dialect "modern" changes syntax and safety rules; it does not switch on Extended-only commands or language features.

Unrecognised names are rejected at compile time, and the literal is case sensitive - "Modern" is not "modern".

For the full story, see the dialects language reference.

See also: Include, Local, Global, Type.

Example

Dialect "modern"

Type Counter
    Field value:Int
End Type

Local counter:Counter=New Counter
counter.value=41
counter.value=counter.value+1

If counter.value<>42 Then RuntimeError "Dialect example failed"
Print "Modern dialect counter: "+counter.value

Delete counter
End

Index