Skip to content
HN On Hacker News ↗

Zero C#: C# with nothing underneath

▲ 178 points • 136 comments • by reverseblade2 • 2d ago • HN discussion ↗

Pangram verdict · v3.3

We believe this text is mainly AI, with some human-written content.

98 %

AI likelihood · overall

AI
2% human-written 98% AI-generated
SEGMENTS · HUMAN 1 of 14
SEGMENTS · AI 13 of 14
WORD COUNT 683
PEAK AI % 100% · §1
Analyzed
Nov 21
backend: pangram/v3.3
Segments scanned
14 windows
avg 49 words each
Distribution
2 / 98%
human / AI fraction
Verdict
AI
Pangram v3.3

Article text · 683 words · 14 segments analyzed

Human AI-generated
§1 AI · 100%

A fork of bflat compiles C# straight to a small native program: no .NET runtime, no garbage collector, nothing to install where it runs. You keep C#'s syntax, type checking and generics. Memory comes from arenas you free all at once, and a small library gives you strings, collections, input and output on those terms. The same source runs on Linux, macOS and Windows, on WebAssembly, and on DOS on a 386. // Read into a stack buffer: nothing allocated per answer. Span<char> buffer = stackalloc char[32]; Out.Write($"Q{i}: {a} + {b} = "); int length = In.ReadLine(buffer); // Kept until the end, so it goes into an arena. mistakes.Add(Str.Format(keep, $"{a} + {b} = {a + b}, not {value}")); From the quiz the tutorial builds, step by step. The language stays, the runtime goes The compiler still checks everything it checks in .NET. What's missing is what a runtime would do while your program runs. You keep C# 15Unions, extension members and the new memory safety rules. Real genericsA specialized copy for each type, and static abstract members. Interfaces and virtual methodsDefault interface methods, casts, is and as. Records, tuples, anonymous typesValue equality, with, and the generated ToString. Lambdas and queriesWhere, Select and GroupBy, from a small library instead of LINQ. ThreadsParallel.For runs a loop on every core. You do without Garbage collectorArenas free their memory all at once, when you say. .NET runtimeHello world is 11 KB on Windows and 40 KB on Linux, with nothing to install. Catching exceptionsthrow ends the program. Return errors as unions. Reflection and asyncA type can be compared, but it has no name. One program, five machines The hello-world sample, unchanged, built for each target. Each build is checked by the same test suite, which requires the same output everywhere.

§2 AI · 100%

$ ./build.sh Minimal $ ./run.sh Minimal Hello from zero-mode!

§3 AI · 100%

$ wc -c bin/Minimal 39848 bin/Minimal Linux, x64 or arm64 A native program that needs only the C library. On macOS it builds and runs in a container.

§4 AI · 98%

$ ./build.sh --mac Minimal $ bin/mac/Minimal Hello from zero-mode!

§5 AI · 87%

$ wc -c bin/mac/Minimal 64728 bin/mac/Minimal macOS on Apple Silicon A native Mac program: bflat compiles it, the Mac's own clang links it. No container to run it.

§6 Human · 0%

$ ./build.sh --win Minimal $ ./run.sh --win Minimal Hello from zero-mode!

§7 AI · 100%

$ wc -c bin/win/Minimal.exe 10752 bin/win/Minimal.exe Windows x64 A console program on Windows' own C library, built from Linux or macOS. Tested under Wine. $ ./build.sh --wasm Minimal $ ./run.sh --wasm Minimal Hello from zero-mode!

§8 AI · 100%

$ wc -c bin/wasm/Minimal.wasm 15833 bin/wasm/Minimal.wasm WebAssembly A WASI module, through NativeAOT-LLVM.

§9 AI · 100%

Runs under wasmtime.

§10 AI · 98%

C:\>D: D:\>PROGRAM Hello from zero-mode!

§11 AI · 100%

D:\>DIR PROGRAM.EXE PROGRAM EXE 16,384 D:\> DOS on a 386 The same bitcode compiled for a 386, run by the HX DOS extender. Tested on Bochs's i386 model.

§12 AI · 100%

What's different, and what you get Without a runtime, a few things work differently. Each has a page that explains why and what to do instead. Memory is yours to free There is no garbage collector, so new is never freed. Arenas hand out memory and free it all at once, one per lifetime. Memory without a garbage collector Text without throwaway strings Out.Line($"...") formats straight into the output buffer, and In.ReadLine reads into a span. Strings that must last go into an arena. Strings without a garbage collector Collections that live in arenas List, Dict, and their versions for references and string keys, all handles into an arena. Choose a collection C# 15, with the safety rules on Every program compiles under the updated memory safety rules: creating a pointer is safe, reading through one is marked and explained. The memory safety rules Where to start If you're new to it, these four pages take you from nothing to an interactive program.

§13 AI · 100%

InstallThe bflat fork and the prerequisites.

§14 AI · 100%

Your first programBuild it, run it, see how small it is. Run it on DOSThe same program under FreeDOS, in an emulator. The tutorialA quiz: output, input, bad input, arenas. Looking for something specific? The task guides answer one question each, and the reference lists every type in the library.