Skip to content

Toit versus other programming languages#

Toit Python
Current object this self
Single line comments // #
Logical 'and', 'or' and 'not' operators and or not and or not
Shift left, right, unsigned right << >> >>> << >> (no unsigned shift)
Integer division / (on integer types) //
Integer sizes 64 (arbitrary)
Statement grouping (indent) (indent)
Define a class Foo that inherits from Bar class Foo extends Bar: class Foo(Bar):
Define constructor for class Foo constructor x: def __init__(self, x):
Define constructor for class Foo
that calls constructor of superclass Bar
constructor x:
  super x
def init(self, x):
  super(Bar, self).init(x)
Constructor that assigns to fields constructor .x:
def init(self, x):
  self.x = x
Check object has type bar is Foo isinstance(bar, Foo)
Check object does not have type bar is not Foo not isinstance(bar, Foo)
Call a method foo with two arguments foo x y foo(x, y)
Declare a member variable in a class
x := null
x := ?
x/int := 0
x/int := ?
self.x = null
Declare a local variable in a method
x := null
x := ?
x/int := 0
x/int := ?
x = null
Define a constant X ::= 0
Define a constant in a class static X ::= 0
Define a top-level function foo x y: def foo(x, y):
Define an instance method in a class foo x y: def foo(self, x, y):
Define a static method in a class static foo x y
If statement if condition: if condition:
Fixed loop end.repeat: | i | for i in range(end):
Three-part for loop for i := 0; i < end; i++:
Iterate over collection collection.do: | x | for x in collection:
While loop while condition: while condition:
Import local from library import .library
Import from library import library import library
Import into current namespace import library show * from library import *
Print/log print "Hello" print("Hello")
Print with interpolation print "Hello $name" print("Hello %s" %(name))
Interpolate with padding print "Hello $(%9s name)" print("Hello %9s", %(name))
Toit C++
Current object this this
Single line comments // //
Logical 'and', 'or' and 'not' operators and or not && || ! (or and or not)
Shift left, right, unsigned right << >> >>> << >> >> (on unsigned type)
Integer division / (on integer types) / (on integer type)
Integer sizes 64 8/16/32/64...
Statement grouping (indent) {}
Define a class Foo that inherits from Bar class Foo extends Bar: class Foo : public Bar {
Define constructor for class Foo constructor x: Foo(int x) {
Define constructor for class Foo
that calls constructor of superclass Bar
constructor x:
  super x
Foo(int x) : Bar(x) {
Constructor that assigns to fields constructor .x: Foo(int x) : x(x) {
Check object has type bar is Foo (dynamic_cast<Foo*>(bar) != null)
Check object does not have type bar is not Foo (dynamic_cast<Foo*>(bar) == null)
Call a method foo with two arguments foo x y foo(x, y);
Declare a member variable in a class
x := null
x := ?
x/int := 0
x/int := ?
int x;
int x = 0;
Declare a local variable in a method
x := null
x := ?
x/int := 0
x/int := ?
int x;
int x = 0;
Define a constant X ::= 0 const int X = 0;
Define a constant in a class static X ::= 0 static const int X = 0;
Define a top-level function foo x y: int foo(int x, int y) {
Define an instance method in a class foo x y: int foo(int x, int y) {
Define a static method in a class static foo x y static int foo(int x, int y) {
If statement if condition: if (condition) {
Fixed loop end.repeat: | i | for (int i = 0; i < end; i++) {
Three-part expression loop for i := 0; i < end; i++: for (int i = 0; i < end; i++) {
Iterate over collection collection.do: | x | for (auto x : collection) {
While loop while condition: while (condition) {
Import local from library import .library #include "file"
Import from library import library #include <file>
Import into current namespace import library show * #include <file> using namespace file;
Print/log print "Hello" cout << "Hello\n"
Print with interpolation print "Hello $name" cout << "Hello " << name << "\n";
Interpolate with padding print "Hello $(%9s name)" printf("Hello %9s\n", name);
Toit Java
Current object this this
Single line comments // //
Logical 'and', 'or' and 'not' operators and or not && || !
Shift left, right, unsigned right << >> >>> << >> >>>
Integer division / (on integer types) / (on integer type)
Integer sizes 64 8/16/32/64
Statement grouping (indent) {}
Define a class Foo that inherits from Bar class Foo extends Bar: public class Foo extends Bar {
Define constructor for class Foo constructor x: public Foo(int x) {
Define constructor for class Foo
that calls constructor of superclass Bar
constructor x:
  super x
public Foo(int x) {
  super(x);
Constructor that assigns to fields constructor .x:
Foo(int x) {
  field_x = x;
Check object has type bar is Foo bar instanceof Foo
Check object does not have type bar is not Foo !(bar instanceof Foo)
Call a method foo with two arguments foo x y foo(x, y);
Declare a member variable in a class
x := null
x := ?
x/int := 0
x/int := ?
int x;
int x = 0;
Declare a local variable in a method
x := null
x := ?
x/int := 0
x/int := ?
int x;
int x = 0;
Define a constant X ::= 0
Define a constant in a class static X ::= 0 public static final int X = 0;
Define a top-level function foo x y:
Define an instance method in a class foo x y: public int foo(int x, int y) {
Define a static method in a class static foo x y public static int foo(int x, int y) {
If statement if condition: if (condition) {
Fixed loop end.repeat: | i | for (int i = 0; i < end; i++) {
Three-part expression loop for i := 0; i < end; i++: for (int i = 0; i < end; i++) {
Iterate over collection collection.do: | x | for (Foo x : collection) {
While loop while condition: while (condition) {
Import local from library import .library
Import from library import library
Import into current namespace import library show * import com.example.Class;
Print/log print "Hello" System.out.println("Hello");
Print with interpolation print "Hello $name" System.out.printf("Hello %s\n, name);
Interpolate with padding print "Hello $(%9s name)" System.out.printf("Hello %9s\n, name);
Toit JavaScript
Current object this this
Single line comments // //
Logical 'and', 'or' and 'not' operators and or not && || !
Shift left, right, unsigned right << >> >>> << >> >>>
Integer division / (on integer types) Math.trunc(x / y)
Integer sizes 64 32, 53
Statement grouping (indent) {}
Define a class Foo that inherits from Bar class Foo extends Bar: class Foo extends Bar {
Define constructor for class Foo constructor x: constructor(x) {
Define constructor for class Foo
that calls constructor of superclass Bar
constructor x:
  super x
constructor(x) {
  super(x);
Constructor that assigns to fields constructor .x:
constructor(x) {
  this.x = x
Check object has type bar is Foo bar instanceof Foo
Check object does not have type bar is not Foo !(bar instanceof Foo)
Call a method foo with two arguments foo x y foo(x, y)
Declare a member variable in a class
x := null
x := ?
x/int := 0
x/int := ?
this.x = null
Declare a local variable in a method
x := null
x := ?
x/int := 0
x/int := ?
var x = null
Define a constant X ::= 0 const X = 0
Define a constant in a class static X ::= 0
Define a top-level function foo x y: function foo(x, y) {
Define an instance method in a class foo x y: foo(x, y) {
Define a static method in a class static foo x y
If statement if condition: if (condition) {
Fixed loop end.repeat: | i | for (var i = 0; i < end; i++) {
Three-part expression loop for i := 0; i < end; i++: for (var i = 0; i < end; i++) {
Iterate over collection collection.do: | x | for (var x in collection) {
While loop while condition: while (condition) {
Import local from library import .library
Import from library import library var library = require('library');
Import into current namespace import library show *
Print/log print "Hello" console.log("Hello")
Print with interpolation print "Hello $name" console.log("Hello " + name + "\n")
Interpolate with padding print "Hello $(%9s name)"