Welcome to THT
However, there are cases where THT is more tightly defined than its counterparts. For example, identifiers are always camelCase.
Because of these small constraints, THT code tends to be simpler and more consistent — within your own projects and code online. This frees up more of your “cognitive bandwidth” so you can focus on higher-level problems while building your app.
If you’re a beginner, we hope you find THT easy to learn and that it helps you develop good habits from the start. The concepts in THT should make it easier to learn other programming languages as well.
We will link to THT-specific configurations in the future. If you create one for your editor, let us know!
A Very Simple Program
Let’s start with a one-line program.
As you can probably guess, it prints this to the browser:
How It Works
Let’s look at each part:
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
// ✖ 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!'); ^
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.
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 lineWidth=(10+5)~'px'; // ✔ 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. let 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. let 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.)
TODO's. Record “To Do” reminders or other notes for the future.
// TODO: add in the rest of the seven dwarves let dwarves = ['Sleepy', 'Sneezy', 'Doc'];
Surrounding text with
*/ creates a multi-line comment block.
/* This is a multi-line comment. */
The Right Balance
Instead of writing long comments, try to make the code itself more self-explanatory, by using clearer variable names and organizing your code into smaller, simpler functions.
Rule of Thumb: Comments should explain the “why” of the code. The code itself already tells you the “what”.