Nox
Download

Tutorial

Tutorial

This tutorial teaches Nox by building up small, complete programs. It assumes you can read a little Python or any similar language; it does not assume you know anything about types, compilers or memory management. Every code block compiles, and every block followed by its output was run to produce it.

Chapter You will learn
1. Hello, Nox install check, noxc run, noxc build, projects
2. Values and types int, float, str, bool, annotations, f-strings, conversions
3. Control flow if, while, for, range, break/continue
4. Functions parameters, defaults, keyword arguments, closures, lambdas
5. Collections lists, dictionaries, sets, tuples, comprehensions
6. Classes classes, inheritance, special methods, protocols, generics
7. Errors exceptions, finally, with, defer
8. Modules and packages multi-file projects, nox.json, dependencies
9. Concurrency tasks, channels, fan-out/fan-in
10. A small web service HTTP server, routing, JSON
11. Files and JSON reading and writing files, directories, parsing and producing JSON
12. Testing noxc test, assertions, TestSuite, testing handlers
13. Generics and protocols one function or container for many types, shape-based interfaces
14. Databases SQLite, prepared statements, transactions, PostgreSQL and MySQL
15. Command-line tools arguments, environment, input, exit codes, running programs
16. WebAssembly and the browser targets, capabilities, running in a page, the Playground
17. Publishing a package nox.json, tags, noxc login, noxc publish
18. Next steps where to go from here
Recipes short answers: word counts, grouping, tables, retries, tasks

Conventions#

Commands you type in a terminal are shown in sh blocks. Nox source is shown in nox blocks; when a block is followed by an output block, that is exactly what the program prints. Compiler error messages are English; branch on the error kind and the exit status, not on the wording.

If you want to experiment as you read, save a block as hello.nox and run noxc run hello.nox (see Install if noxc is not available yet) — or paste it into the Playground and run it in your browser without installing anything.