Sometimes, it is impossible to initialize a variable to a valid value where it is declared. In these cases, it should be left uninitialized rather than initialized to some phony value.
Enhance readability by ensuring that all concepts are uniquely represented. Reduce the chance of error by side effects.
By keeping the operations on a variable within a narrow scope, it is easier to control the effects and side effects of the variable.
ready as Bool = true while ready do //Do something end
ready as Bool = true // Other stuff.... while ready do //Do something end
These statements should be used only if they prove to give a higher readability than their structured counterparts.
if (elementNo < 0) or (elementNo > maxElement) or elementNo = lastElement then //Do something endShould be replaced by:
isFinished as Bool = (elementNo < 0) or (elementNo > maxElement)
isRepeatedElement as Bool = elementNo = lastElement
if isFinished or isRepeatedElement then
//Do something
end
By assigning boolean variables to expressions, the program gets automatic documentation. The construction will be easier to read and debug.
isError as Bool = readFile (fileName) if not isError then //Do something else //Handle the error end
Makes sure that the exceptions do not obscure the normal path of execution. This is important for both the readability and performance.
file = openFile (fileName, "w") if file /= null then //Do something end
if (file = openFile (fileName, "w")) is not null then //Do something end
Conditionals with executable statements are very difficult to read. This is especially true for new programmers.
d = s / SECONDS_PER_DAY timeout = DEFAULT_TIMEOUT
d = s / 86400 timeout = 1000
total = 0.0 speed = 3.0 sum = (a + b) * 10.0;
total = 0; speed = 3; sum = (a + b) * 10;
This emphasizes the different nature of integer and floating point numbers, even if their values might happen to be the same in a specific case.
Moreover, as in the last example above, it emphasizes the type of the assigned variable (sum) at a point in the code where this might not be evident.
total as Real = 0.5f
total as Real = .5f
The number and expression system in Studio is borrowed from mathematics and one should adhere to mathematical conventions for syntax wherever possible. In addition, 0.5 is much more readable than .5. There is no way it can be mixed with the integer 5.