Hacker News

G# – A modern .NET language with Go, Kotlin, and Swift ergonomics

Package and Import System

G# uses a Go-inspired package system. Every source file begins with a package declaration, followed by optional import statements for .NET namespaces:

package Hello
import System

Function Declarations

Functions are declared with the func keyword, following Kotlin and Go conventions. The return type appears after the parameter list:

func greet(name string) string {
    return "Hello, ${name}!"
}

Data Classes

G# introduces data class for concise immutable data holders, similar to Kotlin:

data class Person(name string, age int)

Nullable Handling

Nullable types are handled with if let syntax, inspired by Swift:

if let value = nullableVariable {
    // value is non-null here
}

Structured Concurrency

The language provides structured concurrency with scope, enabling safe and predictable async workflows:

scope {
    // concurrent tasks here
}

Compilation

Source code compiles directly to managed .NET assemblies, integrating seamlessly with the .NET runtime and ecosystem.

Example Program

A complete G# program demonstrating the language's ergonomics:

package Hello
import System

func greet(name string) string {
    return "Hello, ${name}!"
}

Console.WriteLine(greet("world"))

Comments

No comments yet. Start the discussion.