H20
In H20, variables are immutable by default. This means you can't easily change the value of the
variable or change its memory address. To make it mutable, you must use the mut keyword
int x = 5
mut int y = 10
H20 uses clean, text-based operators to make logic easy to read:
is for equality (replaces ==)isnot for inequality (replaces !=)not to invert a boolean (replaces !)and for logical AND (replaces &&)or for logical OR (replaces ||)Example:
if (not isGameOver and playerHealth isnot 0) {
print("The fight continues!")
}
Every H20 file is a class. You dont need boilerplate "public static void main" for everything, but your
mainclass's main() is required for the entry point.
public class Main { // Class name must match file name
func main() { // main() is hardcoded to be public, static and returns int no matter what
print("Hello from H20!")
}
}
H20 provides high precision math constants. No more typing 3.14 manually! Sadly x64 hardware had a limit how many decimals it could store.
PI: The ratio of a circle's circumference to its diameter (3.1415926535897931)E: Euler's number, the base of natural logarithms (2.7182818284590451)Example:
float radius = 5.0
float area = PI * (radius * radius)
print("The area is: " + area)