KonLang Tiếng Việt

Compared with other languages

Rust, C and Go are mature languages used in real products, and Kon is not released. This page shows the design differences, and where you should use one of the others today.

The same program

A function changes a list, and another reads it. Each prints 66.

Kon

func addBonus(scores: edit List<i32>, bonus: i32) {
    var at: u64 = 0
    while at < scores.length {
        scores[at] += bonus
        at += 1
    }
}

func total(scores: view List<i32>): i32 {
    var sum: i32 = 0
    var at: u64 = 0
    while at < scores.length {
        sum += scores[at]
        at += 1
    }
    return sum
}

func main(): i32 {
    var scores: List<i32> = list[10, 20, 30]
    addBonus(edit scores, 2)
    print(total(scores))
    return 0
}
66

Rust

fn add_bonus(scores: &mut Vec<i32>, bonus: i32) {
    for score in scores.iter_mut() {
        *score += bonus;
    }
}

fn total(scores: &[i32]) -> i32 {
    scores.iter().sum()
}

fn main() {
    let mut scores = vec![10, 20, 30];
    add_bonus(&mut scores, 2);
    println!("{}", total(&scores));
}

C

#include <stdio.h>

void add_bonus(int *scores, size_t count, int bonus) {
    for (size_t at = 0; at < count; at++) {
        scores[at] += bonus;
    }
}

int total(const int *scores, size_t count) {
    int sum = 0;
    for (size_t at = 0; at < count; at++) {
        sum += scores[at];
    }
    return sum;
}

int main(void) {
    int scores[] = {10, 20, 30};
    add_bonus(scores, 3, 2);
    printf("%d\n", total(scores, 3));
    return 0;
}

Go

package main

import "fmt"

func addBonus(scores []int, bonus int) {
	for at := range scores {
		scores[at] += bonus
	}
}

func total(scores []int) int {
	sum := 0
	for _, score := range scores {
		sum += score
	}
	return sum
}

func main() {
	scores := []int{10, 20, 30}
	addBonus(scores, 2)
	fmt.Println(total(scores))
}

The Kon, Rust and C versions are compiled and run to check this page. Go is not installed on the machine that checks it, so the Go version has not been compiled here.

Kon has no iterators with closures yet, so its loops are longer than Rust's or Go's. In return, edit scores at the call shows that the list changes. Go's call looks the same whether or not it does.

Side by side

KonRustCGo
Freeing memoryOwnershipOwnershipBy handGarbage collector
Memory safety checkedCompile time, by design; no independent attack campaign yetCompile time, proven in wide useNot by the languageAt run time
Lifetime annotationsNoSometimesNoNo
Change shown at the calledit x&mut xNot alwaysNot always
Index past the endStopsStopsUndefinedStops
Integer overflowWrapsStops in debug, wraps in releaseUndefined when signedWraps
NullNone; OptionNone; OptionYesYes
ThreadsNot yetCheckedUncheckedGoroutines
Libraries availableVery fewManyVery manyMany
Stable releaseNoYesYesYes

Speed and program size were measured against C and Rust on the Performance page. Go has not been measured.

Compared with Rust

Rust is the closest, and Kon's ownership follows the same idea. Kon's aim is to reach a similar safety without lifetime annotations, using plain words at the call. That simplicity has to prove itself: Rust's model has years of real use and formal study behind it, and Kon's does not. Rust also does far more today.

Compared with C

Kon aims for C's speed and small programs, with memory errors caught instead of left to chance. C runs nearly everywhere and every other language can talk to it, which Kon cannot match. Kon can call C, and passing pointers across that boundary is not established yet.

Compared with Go

Go is also meant to be easy to read, and it gets its safety from a garbage collector, which costs pauses and memory but is simple to use. Kon has no collector, so you think about ownership in exchange for steadier timing. For network services, Go is the practical choice: Kon has sockets and a one-thread server, but no threads, HTTP or TLS yet.

When to choose Kon

Today, choose Kon to try the language, follow its progress, or write small Windows tools and games for fun.

Do not choose Kon yet for anything that has to keep working: it has no stable release, and its code can still change. The same goes for anything needing threads, HTTP or TLS, other operating systems or many libraries.