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

Welcome to THT


If you already know PHP, then THT will feel familiar. It’s still just a dynamic, curly brace language with $ variables.

While THT provides a lot of handy shortcuts, you’ll see that it also adds a few limitations. For example, identifiers are always camelCase.

We like to think of these conventions as guard rails. They aren’t meant to cage you in, but to keep you moving forward.

They will help you avoid common mistakes that all programmers tend to make, and also free up more of your “cognitive bandwidth” to focus on higher-level problems, instead of getting sidetracked with trivial bugs & decisions.

If you’re a beginner, this means you will develop good programming habits from the start — habits that will be useful in other languages, as well.


Syntax Highlighting 

When editing .tht files, try setting your editor to use PHP or JavaScript syntax highlighting, since the languages are similar.

If you use TextMate or Sublime Text, you can download the THT.tmbundle to add syntax highlighting support.

A Very Simple Program 

Let’s start with a one-line program.

print('Hello World!');

As you can probably guess, it prints this to the browser:

Hello World!

How It Works

Let’s look at each part:

1) print is the command, or function.

print('Hello World!');

2) The text, or string, is surrounded by single quote marks. (The quotes are not printed.)

// ✖ NO
print(Hello World!);

// ✔ YES
print('Hello World!');
      ^            ^

3) Our string is passed into the print function by surrounding it with parentheses.

// ✖ NO
print 'Hello World!';

// ✔ YES
print('Hello World!');
     ^              ^

4) Every statement ends in a semicolon, just like a period at the end of a sentence.

// ✖ NO
print('Hello World!')

// ✔ YES
print('Hello World!');

JargonIn the correct terminology, we’d say we are calling the 'print' function, with the argument 'Hello World!'.


The print function is a quick way to check your code as it runs. It’s mainly for you, as the developer, to experiment and debug.

If you try to print a data type other than text, it will be displayed in a readable format.

To send HTML output to the browser, you will use the Response module, as described in How to Create a Basic Web App.

Format Checker 

In the process of getting your program to run, it’s easy to end up with code that is a bit messy. It happens to everyone, whether they are new or experienced.

Messy code can be frustrating and stressful to work with, because it is harder to read and creates places where bugs can hide.

To help you write clean code, THT includes a Format Checker. It provides instant feedback about how to format your code so that it’s easier to understand and work with.

Spacing is especially important!


// ✖ NO

// ✔ YES  Cleaner spacing
$lineWidth = (10 + 5) ~ 'px';

Read More: Format Checker


A comment is a line starting with //.

Comments are not executed as part of the program. A comment can appear on a line by itself, or at the end of a code line.

// A standalone comment.
// Here is another line.

$a = 1;  // Or next to a line of code.

How to Use Comments

Comments are useful for a few things:

Explaining code. Explain parts of the program to help any future reader (including you!) modify it later.

// Apply the Zuckerdorf Friendship Formula to determine
// how close this friend is to the current user.
$friendLevel = ($numFriendsInCommon * 1.2345) + 42;

Disabling code. Temporarily remove lines of code while debugging. (Be careful not to clutter your files with too much unused code.)

// showWidgets(widgets);

TODO's. Record “To Do” reminders or other notes for the future.

// TODO: add in the rest of the seven dwarves
$dwarves = ['Sleepy', 'Sneezy', 'Doc'];

Multi-line Comments

Surrounding text with /* and */ creates a multi-line comment block.

    This is a

The Right Balance

TipComments are useful, but are in some ways a necessary evil, because they can sometimes distract from the actual code.

Instead of writing long comments, try to make the code itself more self-explanatory, by using clear variable names and organizing it into small, simple functions.

Rule of Thumb: Comments should explain the “why” of the code. The code itself already tells you the “what”.