Feature | TypeScript | Nim |
---|---|---|
Execution model | JavaScript code (Compiler) | JavaScript code (Compiler) |
Written using | TypeScript | Nim |
License | Apache | MIT |
Version (Mayor) | 3.x |
1.x |
Typing | Static | Static |
Meta-programming | β #issue-13252, Decorators are limited | βοΈ template, macro |
int8/16/32/64 types | β | βοΈ |
float32/float64 types | β | βοΈ |
Char types | β | βοΈ |
Subrange types | β #issue-225324972 | βοΈ |
JSON types | β #issue-56296923 | βοΈ |
Regex types | β #issue-128264906 | βοΈ |
Option types | β | βοΈ |
Dependent types | β | βοΈ |
Operator Overloading | β | βοΈ |
Custom Operators | β | βοΈ |
Enum types | βοΈ | βοΈ |
Immutability | Limited, readonly keyword |
βοΈ |
Function Arguments Immutability | Mutable | Immutable |
Full DOM API | βοΈ | βοΈ |
NodeJS integration | βοΈ | βοΈ |
Generics | βοΈ | βοΈ |
Type inference | βοΈ | βοΈ |
Closures | βοΈ | βοΈ |
Object-Oriented | βοΈ | βοΈ |
Methods | βοΈ | βοΈ |
Exceptions | βοΈ | βοΈ |
Anonymous Functions | βοΈ | βοΈ |
Arrow Functions | βοΈ | βοΈ |
Array Comprehensions | βοΈ | βοΈ |
Formatted String Literals | βοΈ | βοΈ |
FFI | βοΈ JS only | βοΈ C/C++/JS |
Async | βοΈ | βοΈ |
Regex | βοΈ | βοΈ |
Self-Documentation comments | βοΈ | βοΈ |
Package Publishing | βοΈ | βοΈ |
Package Manager | βοΈ | βοΈ |
Code AutoFormatter | βοΈ via NPM | βοΈ Nimpretty |
Syntax similar to | JavaScript | CoffeeScript or Python |
Variables
Creating a new variable uses var
or let
or const
.
Nim has immutability and compile-time function execution.
You can assign functions to variables.
-
const
is different from TypeScript by being truly immutable.
Declaration | Compile-Time | Run-Time | Immutable | Requires Assignment |
---|---|---|---|---|
var |
β | βοΈ | β | β |
let |
β | βοΈ | βοΈ | βοΈ |
const |
βοΈ | β | βοΈ | βοΈ |
Compile-Time Function Execution
Nim has Compile-Time Function Execution that allows you to run Backend-like code at compile-time and use it on Frontend at run-time.
Compile-time FFI is also possible, you can pull data from C/C++ libs at compile-time and use it on Frontend at run-time.
Most code that works at compile-time and NimScript also tends to work for Frontend.
Example: Compile-time recursive file system walk module.
Svelte
Nim has some similarities with Svelte for Frontend, but at the time of writing Svelte does not fully supports TypeScript.
Svelte can not do Backend (is not designed to).
Build Modes
Feature | Release Build | Debug Build |
---|---|---|
Speed | Fast | Slow |
File Size | Small | Big |
Optimized | βοΈ | β |
Tracebacks | β | βοΈ |
Run-time checks | β | βοΈ |
Compile-time checks | βοΈ | βοΈ |
assert |
β | βοΈ |
doAssert |
βοΈ | βοΈ |
- Once compiled it wont need Nim anymore, 100% dependency-free.
Hello World
echo "Hello World"
Console Hello World:
console.log("Hello World")
Thank you for playing
There's bridged Gitter, Matrix, Telegram, IRC, Discord for Nim, come say Hi.
Nim Homepage
Learn Nim today.
Grupo de Telegram en EspaΓ±ol.
π
Top comments (0)