Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.

Features Handbook

Nicolas Schmidt edited this page Dec 15, 2023 · 8 revisions

Shake Docs Header

1. Operators

1.0 Mathematical operators

Standard Calculations

10 + 10 // plus
1010 // minus
10 * 10 // multiply
10 / 10 // divide
10 ** 3 // power (>> 10 * 10 * 10)

Priorities (From highest to lowest):

  1. brackets
  2. square
  3. multiply, divide
  4. plus, minus

Brackets are processed prioritised.

10 – (3 + 10) // >> -3

1.1 Logical operators

To compare different values we have 5 comparison operators

== // equals
>= // bigger or equal
<= // lower or equal
> // bigger
< // lower

You can use them like that

10 > 9 // Will return true because 10 is bigger than 9
10 > 10 // Will return false because 10 is not bigger than 10

1.2 Boolean Operators

There are 3 boolean operators to concatunate booleans

|| // or operator returns true if at least one of both provided values is true
^ // xor operator returns true if just one, but not two of both provided values, is true
&& // and operator only returns true if both provided values are true 

2. Variables

2.0 Variable Initialization

There are two ways that are fine and do basically the same

int i;
var i : int;

Variable initialization with value assignment

int i = 0
var i : int = 0

2.1 Simple data types

There are a few basic variable types integrated in the compiler

Type Size Description
byte 1 byte Stores whole numbers from -128 to 127
short 2 bytes Stores whole numbers from -32,768 to 32,767
int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
boolean 1 bit Stores true or false values
char 2 bytes Stores a single character/letter or ASCII values

2.1 Complex data types

Complex data types can store more than just a number, they can store multiple values. They are base of the object oriented programming

Type Description
String Strings store text, text is no simple data, it is stored in a complex data type.

2.2 Variable Assignments

Standard assignment

i = 0 

Calculation assignments Only works for supporting types, e.g. numbers

i += 2 // Add to variable
i -= 2 // Subtract from variable
i *= 2 // Multiplicate variable
i /= 2 // Divide variable
i **= 3 // Power variable

Boolean Assignments

bool1 |= bool2 // Saves into bool1 if either bool1 or bool2 is true
bool1 &= bool2 // Saves into bool1 if bool1 and bool2 are both true
bool1 ^= bool2 // Saves into bool1 if either bool1 or bool2, but not both, are true

2.3 Constants

Constants are basically variables with fixed values You can use a standard variable initialization with the final keyword before. Constants need a value when they are initialized because you can’t assign a value later

final int i = 0

DO NOT use this syntax with var, the compiler will process it, but it is bad Syntax, just remove the var keyword int this case

final var i : int = 0 // << Bad Syntax
const i : int = 0 // << Better Syntax

3 Statements

3.0 if-else Statement An if-statement needs a boolean input and executes an action if the boolean value is true

if ( condition ) { … }

if the statement is false you can also execute an else statement

if ( condition ) { … } 
else { … }

If the code the if-statement should execute is just one line long, you can also write them inline

if ( condition ) doSomething();
else doSomethingElse();

You can also chain if-statements

if ( condition ) { … }
else if ( condition ) { … }
else { … }

3.2 Loops

3.2.0 While-Loops

While loops are the first basic loops. They just get a condition and execute as long as the condition is true

while ( condition ) { … }

They can also be written inline

while ( condition ) doSomething();

3.2.1 Do-While-Loops

Do-While are much like while loops, but they execute once before the condition is checked

do { ... } while ( condition );

They can also be written inline

do doSomething(); while ( condition );

3.2.2 For-Loops

For loops are designed to loop with a counter. You can for example count to ten and run a function ten times

for(int i = 0; i < 10; i++>) { ... }

They can also be written inline

for(int i = 0; i < 10; i++>) doSomething();

4 Functions

Functions can be written in two different styles. You can write them in a JavaScript style:

function doSomething() { ... }

The other variant is to code them in a c-style:

void doSomething() { ... }

4.1 Return types

A function can has a declared return type. C-Style always declares a return-type. If your function returns an int for example the function declaration works like that in c-style

int returningFunction() { ... }

...and in JavaScript-Style

function returningFunction() : int { ... }

If a function returns nothing, it's type is void

C-Style:

void doSomething() { ... }

JavaScript-Style:

function doSomething(): void { ... }

4.2 Function calls

Function calls always work like that

myFunction();

You can also put the parameters inside the function call

println(42);

4.3 declaring function parameters

You can declare function parameters in the brackets. There are also two styles, C-Style and JavaScript style.

C-Style parameter declaration:

function f(int i) { ... }

JavaScript-Style parameter declaration:

function f(i : int) { ... }