Welcome to THT
THT is like a shiny, cleaned up version of PHP from the future.
Some core parts are still the same, like $
variables, curly braces {}
, and a primary focus on web development.
However, every part of THT was thoughtfully re-designed from the bottom up, with the goal of providing better safety and usability.
What does that mean? Here are some examples:
- Streamlining the syntax to reduce visual clutter. (e.g. removing semicolons, using dot notation, etc.)
- Organizing the standard library into modules and classes.
- Baking in conventions to eliminate small decisions. (e.g. variable names are camelCase)
- Using smart defaults, especially with regard to security. (e.g. all output is escaped)
- Providing clear feedback when things go wrong.
Some of these changes might seem a bit strict at first, especially if they are different from what you are used to.
However, try to think of them as guard rails on a twisty mountain road. They’re set up to keep you moving forward safely, not to cage you in.
If you’re new to programming, this will help you learn good coding habits very quickly. These habits will be useful when you program in other languages, as well.
Enjoy!
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 of the code above.
print
is the command, or function.
print('Hello World!') ^^^^^
Everything inside the parentheses ()
is sent to the print
function.
print('Hello World!') ^^^^^^^^^^^^^^
We are sending it a string of text, which is surrounded by single quote marks '
. (The quotes are not printed.)
print('Hello World!') ^ ^---- single quotes
Printing
The print
function is a quick way to check your code as it runs.
Your print messages will appear in an overlay panel on your page.
You can print just about any kind of data, and THT will display it in a human-readable format.
print('Hello THT!') print(1234)
Line Endings
In PHP, a semicolon ;
is used to mark the end of statements.
THT is different. It uses one statement per line.
print('Hello!') ^---- No semicolon ;
This approach reduces reduces visual noise and eliminates common “missing semicolon” errors.
Line Wrapping
If you need to extend a statement beyond one line, start the next line with an operator, or wrap the expression in parens (...)
.
// Operators on the next line $price = $basePrice + $taxes - $discount // Or with parens (recommended) $price = ( $basePrice + $taxes - $discount )
Format Checker
In the process of getting our code to work correctly, we often overlook small inconsistencies in our code (e.g. how names are spelled, how it is indented, etc.).
However, these small mistakes can build up over time, making your code more difficult to read and even creating places where bugs can hide. (When it gets really bad, we call this “spaghetti code”.)
To help keep your code clean and consistent, THT automatically runs your code through a Format Checker, which will tell you right away if anything needs to be fixed.
Spacing is especially important!
Example:
// ✕ NO $lineWidth=(10+5)~'px' // ✓ YES Cleaner spacing $lineWidth = (10 + 5) ~ 'px'