Skip to content
NorscodeNorscode

Types that catch errors before you run

ArticleBy the Norscode project

Static typing and nc check catch a whole class of errors before the program even starts.

Errors caught before running wrong type missing function wrong value nc check nc run — clean

There are two moments an error can show up: while you are writing the code, or while the user is running it. The first is cheap to fix. The second can cost you a phone call in the middle of the night. Norscode moves as many errors as possible to the first.

Types with Norwegian names

Every value in Norscode has a type: tekst, heiltall, boolsk, liste_heltall, ordbok_tekst. Functions say what they take in and what they give back. It is not bureaucracy — it is a contract the compiler can check.

nc check before nc run

The command nc check reads the code and compares the contracts. Send a tekst where a heiltall was promised, or call a function that does not exist, and you are told at once — not first when the code is out in production. A whole class of typos and misunderstandings is caught before the program gets to run.

Why it matters most for large programs

In a small script you hold the whole picture in your head. In a program that grows, you do not. Then static typing is like a safety net under every change: move something, and the compiler tells you if something else no longer fits together. You dare to make changes, because you get told when they break something.

Not in the beginner's way

The types are there, but they are written in Norwegian and read like ordinary text. funksjon storst(tall: liste_heltall) -> heiltall almost tells you by itself what it does. The safety does not cost readability — it adds precision.

What the type check actually catches

Imagine a function promises to take an integer, but you call it with a text. In a dynamic language you might not discover it until the code runs — in the worst case at a user's. nc check catches it at once, before the program gets to start. The same goes for calling a function that does not exist, or forgetting an argument. A whole class of typos and misunderstandings is caught at the cheapest possible moment.

Signatures as documentation

A function signature tells a lot on a single line. funksjon storst(tall: liste_heltall) -> heiltall says that the function takes a list of integers and gives one integer back. You do not need to read the body to know how it is used. In that way the types are also documentation — one that never goes out of date, because the compiler enforces it.

Safety without heaviness

Static typing has a reputation for being cumbersome. In Norscode it is easy to live with: the types have Norwegian names and read like ordinary text, and you write them where it counts — on functions' inputs and outputs — not on every single variable. The result is precision without ceremony: the code says what it means, and the compiler makes sure it keeps its word.

Related

Back to the overview