Version: v0.6.0 - Beta.  We welcome contributors & feedback.  THanks!

Variables & Methods

Variables 

A variable is like a box that contains information (data).

Each variable has a label that starts with $.

Data values are assigned to variables with =.

$location = 'Paris';
$numArtists = 9000;
$isBeautiful = true;

Case Matching

Variable and function names are case-sensitive. They must match exactly.

$numApples = 10;

// ✖ ERROR
// 'A' should be uppercase.
print($numapples);

// ✖ ERROR
// 'print' should be lowercase.
Print('Hello!');

Basic Data Types 

There are 3 basic types of data:

// Numbers
42     // positive
-62    // negative
1.618  // fraction (aka 'floating point' or 'float')

// String (surrounded with single-quotes)
'This is a string!'

// Booleans
true
false

Initializing Variables 

New variables must always be given a value before they are used.

If you’re not sure what to use, pick the “empty” version of the type you need:

$myString = '';
$myNumber = 0;
$myBoolean = false;

Null 

Unlike many other languages, THT does not have a null, nil, or undefined value. (See “The Billion Dollar Mistake”).

If you need a way to represent “nothing”, consider using a Result object, or an empty value for the given type.

Variable Names 

Variables and function names are always written in camelCase format:

Examples:

$user
$userId
$firstName
$isDeleted
$numRecords
$httpVersion
$userHasIphone

Naming Tips

Coming up with good names is one of the most important (and difficult) skills in programming.

Always take the extra time to find names that clearly represent what they are labelling.

Common Guidelines:

Examples:

✖ Bad         ✔ Better
------        ------------
$usr           $user
$fname         $firstName
$nbrPosts      $numPosts
$cmntTxt       $commentText
$banned        $isBanned
$activeTime    $numDaysActive
$distance      $distanceKm
$userList      $users
$active        $activeUsers, $isActive
$a             (be more specific)
$temp          (be more specific)

Methods 

Methods are functions that are attached to data. They are called using the dot . operator.

All built-in data types have methods.

$text = '  Tipsy Turtle  ';

$text.trim();
//= 'Tipsy Turtle' (no extra spaces)

$text.contains('Turtle');
//= true

$text.length();
//= 14  (including spaces)

Methods can be chained together.

$text = '  This is a string!!!  ';

$text = $text.trim().toUpperCase().replace(r'!+', '.');
//= 'THIS IS A STRING.'

Modules

A module is a bundle of related functions. Module names are always UpperCamelCase.

THT comes with essential modules like Math, Date, and Web.

Math.floor(3.15);
//= 3 (rounded down)

Math.pi();
//= 3.1415926535898

Date.now();
//= current timestamp in seconds

File.read('words.txt');
//= (contents of 'words.txt' file)

ReferenceAll built-in modules and methods are listed in the Manual.