Table of Contents

What is programming?

A conversation with your computer

When you use a calculator, you press buttons and it gives you answers. Programming is the same idea, but instead of pressing buttons one at a time, you write a complete set of instructions in advance. The computer reads your instructions and follows them exactly, one by one.

These instructions are written in a programming language. Just like human languages (English, Spanish, Japanese), programming languages have their own vocabulary and grammar. Nyx is one of these languages.

What makes Nyx special?

There are hundreds of programming languages in the world. Each one has a different approach. Nyx was designed with three principles:

Simple — The syntax is clean and minimal. There are no unnecessary symbols or complicated rules. If you can read English, you can read Nyx code.

Fast — Nyx compiles your instructions into a native binary — a file that your computer's processor understands directly. There is no middleman. This makes Nyx programs extremely fast, comparable to C, one of the fastest languages ever created.

Efficient — Nyx programs are tiny. A complete web server fits in 150 kilobytes. A complete database fits in 132 kilobytes. For comparison, most programs today are measured in megabytes or gigabytes.

How does it work?

When you write code in Nyx, this is what happens:

Your code (hello.nx)
    ↓
Nyx compiler (nyx_bootstrap)
    ↓
Machine instructions (hello.ll)
    ↓
Clang linker
    ↓
Native binary (hello) ← your computer runs this directly

You write a text file with instructions. The Nyx compiler reads your text file and translates it into instructions that your processor can understand. The result is a binary — a standalone program that runs on its own, without needing Nyx or anything else installed.

Key terms

Before we begin, here are some words you will see throughout this book:

Program: A set of instructions that a computer follows to do something useful.

Source code: The text file where you write your instructions. In Nyx, these files end in .nx.

Compiler: A tool that translates source code into a binary that the computer can run. The Nyx compiler is called nyx_bootstrap.

Binary: The final result — a file that your computer's processor can execute directly. When you "compile" a program, you are creating a binary.

Terminal: A text-based interface where you type commands. You will use the terminal to compile and run your Nyx programs.

Bug: A mistake in your code that causes it to do something wrong or unexpected. Finding and fixing bugs is a normal part of programming.

Installing Nyx

To write Nyx programs, you need three things:

  1. A text editor — Any editor that can save plain text files. VS Code, Sublime Text, Vim, Notepad++ — any of these work.
  1. The Nyx compiler — This translates your code into a binary.
  1. Clang — A tool that links the compiled code with the runtime. It comes pre-installed on most systems or can be installed with one command.

To install Nyx on Linux or macOS:

curl -sSf https://nyxlang.com/install.sh | sh

To verify the installation:

nyx --version

You should see something like Nyx v0.12.0.

Your first program

Create a file called hello.nx in your text editor and type this:

fn main() {
    print("Hello, World!")
}

Let's break this down:

Compiling and running

Open your terminal, navigate to the folder where you saved hello.nx, and type:

nyx run hello.nx

You should see:

Hello, World!

That's it. You just wrote, compiled, and ran your first program. The nyx run command does two things automatically: it compiles your code into a binary and then runs that binary.

If you want to compile without running (to create a binary you can share or deploy):

nyx build hello.nx
./hello

This creates a binary called hello that you can run anytime, on any compatible machine, without needing Nyx installed.

What just happened?

  1. You wrote instructions in a text file (hello.nx).
  2. The Nyx compiler translated those instructions into machine code.
  3. The resulting binary (hello) ran on your computer and printed text to the screen.

This is the core cycle of programming: write → compile → run. Everything you learn from this point forward is about writing more sophisticated instructions.

Try it yourself

Before moving on, try modifying your program:

  1. Change the message to your name:
fn main() {
    print("Hello, I am learning Nyx!")
}
  1. Add multiple lines:
fn main() {
    print("Line 1")
    print("Line 2")
    print("Line 3")
}
  1. Try making an intentional mistake and see what happens:
fn main() {
    print("This is missing a closing parenthesis"
}

The compiler will show you an error message. Reading and understanding error messages is an important skill — they are the compiler trying to help you find the problem.

Summary

Next chapter: Variables and types →

Next: Variables and types →