Data Types
The following data types are supported:
- Numeric
- Integers
- Decimals
- Positive & Negative
- Strings
- Dates
- Booleans
- True
- False
- Arrays
Strict Typing
The Core scripting language uses a strict typing model.
What is Strict Typing?
- All variables have a "Data Type" (listed above)
- Certain Operations can only be performed on specific Data Types
- Arithmetic operations only work for Numerics
- Strings can only be joined to other strings
- Date functions only work on Date objects
- Comparison Operators take into account the Data Type
What does it mean for me?
You will most often come across this when you have a String that looks like a Number or a Date.
For example, you create a field called "Quantity", you expect users to always enter a number, but you don't actually set the data type on the field to one of the Numeric options.
Then, you build a calculation based on that field: ["Quantity"] * ["Unit Price"] and everything goes great. Until, one of your users starts entering things like "None" or "N/A" etc. Now your calculation is broken.
A strict typing model would prevent you from creating that calculation in the first place. You cannot multiply a String by a Decimal, even if all the Strings contain only numbers.
Another common scenario is a field that you expect to contain a date. But again, if you leave it as a text field and don't set the data type correctly, then users will enter all sorts of random things: "01/04/2023", "01.04.2023", "2023-04-01", even things like "4/2023", "Apr 23", "Friday Yaay", etc.
Common Gotchas
The thing that is often most confusing is how this affects Comparison Operators. Some of the following examples may not work the way you would expect:
| Comparison | Result |
|---|---|
| 1 = 1 | True |
| 1 = "1" | Error: Type Mismatch |
| 10 > 9 | True |
| "10" > "9" | False |
| DATE("2023-02-14") = "14/02/2023" | Error: Type Mismatch |
Conversions
The following functions are provided for converting between Data Types:
| Function | Convert From | Convert To |
|---|---|---|
| STRING() | Numeric | String |
| INT() | String | Integer |
| FLOAT() | String | Decimal |
| DATE() | String | Date |
| FORMAT() | Date | String (d/m/Y) |
Now the comparisons above can be made to work as intended:
| Comparison | Result |
|---|---|
| 1 = 1 | True |
| 1 = INT("1") | True |
| 10 > 9 | True |
| INT("10") > INT("9") | True |
| FORMAT(DATE("2023-02-14")) = "14/02/2023" | True |
Benefits
The benefits come in consistency and predictability. Things that might work as expected in some cases but not others will generally produce an error straight away. This should help you identify potential problems sooner rather than later.
It encourages you to think a bit more up front to avoid unexpected errors later. It helps avoid situations where things appear to work for the particular data you tested on but then fail, in strange and unpredictable ways, when users enter something unexpected.
Drawbacks
The drawbacks are all the exact same reasons. If you are not used to it the results can be unintuitive (some might say confusing and unhelpful). We believe that on balance, the benefits outweigh the drawbacks once you get used to it.