bend

Bend is a statically-typed programming language for the web. It compiles down to readable JavaScript with no runtime library and easily integrates with other JavaScript code.

try it

Enter your Bend code in the top half of the box below and it will be compiled to JavaScript in the bottom half.

get it

Keep in mind that this project is still experimental. It has just recently reached the point of being useful but is still very much unfinished. There are still many more features coming (generics and operator overloading, for example) as well as language and implementation bugs to fix.

The compiler is self-hosting (written in Bend) and is available at https://github.com/evanw/bend. It's also available on npm:

npm install -g bend

After installing, the compiler will be available as the "bend" command.

features

This section is meant to highlight the differences between Bend and other languages and is not meant to be a complete reference. It is roughly structured top to bottom so features later on assume knowledge of previous features. All code examples are live and can be edited, which will update the compiled JavaScript automatically.

Syntax is a blend of C and Python. Control structures use curly braces without parentheses, some operators are keywords instead of symbols, and newlines terminate statements. Single-line comments are part of the grammar so they can be preserved in the output.

Default constructors are automatically generated for classes without a constructor.

Initializer lists provide a shorter way to call constructors. They can only be used where the type can be inferred (as the right-hand side of an assignment or as an argument to a function call).

Lambdas must also be used where the type can be inferred (as the right-hand side of an assignment or as an argument to a function call).

Nullable types are denoted by a question mark after the type. Null safety is ensured by requiring a nullable value to be checked with a match expression before using it.

Match expressions are a concise way to check if a value is of a certain type and then manipulate that value as that more specific type. Each match expression introduces a new scope and variable only for the code that will run if the match expression evaluates to true.

Enums can be simulated using classes and static variables. This is more powerful than the integer constant approach since each instance can hold additional data. To make this more concise, free identifiers in class definitions are automatically converted to static variable declarations that each hold an instance of the class.

Unchecked variables use the type "var" and provide an easy way to integrate with existing code. Type errors are silently ignored for almost all expressions containing unchecked variables.

Sane scoping rules maintain intuitive behavior for variables inside lambdas.

Argument splats allow functions to take an arbitrarily large number of arguments.