Variables

Variables are typed strongly and, most of the time, statically. This means that you have to select a type for each created variable and variables of different types are not mutually assignable, i.e. you cannot set variable of type Person to value of variable of type Team. If you try to do it, CJ Blocks editor won’t let you connect corresponding set and get blocks.

The approach follows the convention of Java and JavaScript (ES6) languages that CJ blocks are translated to. All variables have local scope – they exist only within action or function that creates them and cannot be accessed from code in other actions or functions. The naming approach for variables mimics convention used for names of data types and fields – i.e. you can choose whatever name you deem suitable and include spaces and any Unicode characters. It is perfectly legal to use your native language and alphabet for naming of variables.  Say, you can call variable “meine Variable” (German) or «моя змінна» (Ukrainian).  However, there is an important difference. In generated Java or Java script code references to types and fields are replaced with their numeric identifiers. For the sake of readability, references to variables and not replaced with numbers but are used directly as declared with some escaping done to meet the restrictions imposed by grammar of target languages (i.e. Java or JavaScript). Escaping means replacing not allowed characters with allowed ones. So, in generated code, the variable “meine Variable” would appear as “meine_Variable”. The Builder routine that escapes variable names takes reasonable care to cover common cases but with some effort it might be possible to craft a variable name that won’t get escaped properly and will result in compilation error. If something like that happened, just rename a variable by removing the offending character and build the project again.

To create a variable
To set a variable
To rename a variable – mention a problem with renaming of variables in inner scope