← Code Compare

Hello, World

Every language's smallest complete program: name an entry point and print one line to standard output. Watch how much ceremony each one demands - from Perl's and Python's bare one-liners, to Go's explicit package/func main, to Guji's sub main() (its return type is optional; add : Int only when you want to set the exit code). Notice too how the string reaches the screen: a statement (print), a function (println!), a method, or a top-level expression.

Show: GujiGoOCamlHaskellPerlRakuRustPython
Guji
sub main() {
    $name = "world"
    print("hello, $name")
}

The minimal guji program is just sub main() { ... }: execution begins at main, and a Unit return means it runs and exits cleanly with no boilerplate. The $ sigil is part of the binding's name ($name), and double-quoted strings interpolate it directly with $name. print is a prelude builtin that writes the value plus a newline to standard output; it is one of several real IO builtins (note writes to stderr, plus read_file, open, stdin, and args). guji compiles ahead-of-time to a native binary, so this is the same program whether you run it through the interpreter or guji build it. You only write the sub main(): Int { ...; 0 } form when you want to set the process exit code yourself.

Go
package main

import "fmt"

func main() {
	fmt.Println("Hello, World")
}

A runnable Go program lives in package main and starts at func main(), which takes no arguments and returns nothing. Printing is not a keyword but a call into the standard library's fmt package, so the import "fmt" is mandatory - an unused import is a compile error. Println adds the trailing newline.

OCaml
let () = print_endline "Hello, World"

OCaml has no dedicated main: top-level let bindings execute in order, so let () = ... runs an expression for its side effect and asserts it has type unit. print_endline writes a string followed by a newline, and is part of the always-available Stdlib, so no open is needed.

Haskell
main :: IO ()
main = putStrLn "Hello, World"

A Haskell program's entry point is main :: IO (), a value of type IO () that describes an action the runtime performs. putStrLn writes a String followed by a newline, and is a pure description until main is actually run. The top-level type signature is idiomatic style, though Hindley-Milner inference makes it unnecessary here.

Perl
use strict;
use warnings;

print "Hello, World\n";

Perl has no entry-point function: statements at file scope run top to bottom. print is a builtin list operator, and the \n is explicit because print adds no newline of its own. The use strict; use warnings; pragmas are idiomatic boilerplate that catch typos and unsafe constructs at compile time.

Raku
say "Hello, World";

Raku (formerly Perl 6) ships say, which prints its argument and a trailing newline, so the program is a single statement. Like Perl, it needs no explicit main for a script - though Raku will call a sub MAIN if you define one, wiring command-line arguments to its signature. strict and warnings are on by default.

Rust
fn main() {
    println!("Hello, World");
}

A Rust binary starts at fn main(), which returns () by default. Printing uses println!, a macro (note the !) rather than a function, so the format string is checked at compile time and the trailing newline is implicit. No imports are needed because println! lives in the always-imported prelude.

Python
print("Hello, World")

Python runs a module top to bottom with no required entry point, so a one-line script is a complete program. print is a builtin function (since Python 3) that adds a newline automatically. The common if __name__ == "__main__": guard only matters when a file is meant to be both imported and run directly.