I Tried Hello World in 28 Languages


Ah, classic. You don’t learn programming without running into a variety of tropes. There’s always FooBar (not to be confused with military FUBAR) and sometimes Baz.

Anytown, USA.

Acme Company.

Lorem Ipsum.

…and then there’s “Hello World!”

Whenever you’re learning a new programming language or a new framework of some sort, the classic first lesson is to get a program running that simply prints the words “Hello World!” to the console or screen.

Honestly it’s like a rite of passage. If you’ve never printed “Hello World!” in a language, do you really know it?

So I figured I’d give this a shot in as many languages as I can think of. Why? I have no idea. I enjoy self-inflicted pain, maybe. Also I want to make it seem like I know 28 languages when this is obviously untrue.

C

1
2
3
4
5
6
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}

C was the first language I ever touched. There are some things I like about it. There’s no doubt that both C and C++ are very powerful, performant languages. But man, you can really shoot yourself in the foot if you don’t manage your memory or pointers properly.

These languages are not very newb-friendly.

Try to explain the “#include” directive and preprocessor to a new learner. It also took me a long time to finally understand why we “return 0” in the main function.

5/10

C++

1
2
3
4
5
6
7
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}

Again, if you’re a newb to programming, both the namespace declaration and the redirection operator (“<<”) are probably confusing as hell.

5/10

Java

1
2
3
4
5
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

Not much cleaner. Now you gotta explain what a class is, what “static” means, what “void” means, and what “String[] args” is.

Also, I hate the fact that you have to type 117 characters and 14 words just to print 2 words. Yikes.

5/10

C#

1
2
3
4
5
6
7
8
9
10
11
12
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
}

Oh my god. Imagine teaching all of this to a new coder. Namespaces, classes, static functions, return values, and user input.

Why is there a “Console.ReadKey()” in there? Oh, it’s because when you run this in Visual Studio, it opens in a new window that immediately closes when the program terminates.

So if you don’t wait on user input, you won’t actually see the program’s output because it closes too quickly for you to see it.

Lovely. (◔_◔)

2/10

PHP

1
2
3
<?php
echo "Hello World!";
?>

What kills me is that you have to tell PHP that the code it’s reading is PHP.

Also, PHP inline with HTML is probably the ugliest code I’ve ever seen.

6/10

Ruby

1
puts 'Hello World!'

“puts”? What the hell?

5/10

Python

1
print("Hello World!")

1 line, and it’s impossible to misunderstand what “print” means. Don’t have to gloss over concepts or explain anything complicated to a new programmer. It’s beautiful.

10/10

Bash

1
2
#!/bin/bash
echo "Hello World!"

Not bad. The only hard part here is understanding / explaining the shebang, and, by extension, what different shell interpreters are.

7/10

Perl

1
2
#!/usr/bin/perl
print "Hello World!"

“print” is a little nicer than “echo.” Another shebang though.

8/10

Haskell

1
main = putStrLn "Hello World!"

Ok, I see a “main” keyword. I’m presuming “putStrLn” is the function to print something…

But why are we setting “main” equal to “putStrLn”? What?

4/10

Clojure

1
(println "Hello World")

Nice and clean.

But I’m going to give this a 9/10 because installing and running lein was a pain in the ass.

Scala

1
2
3
4
5
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello World!")
}
}

A little messier than Java. That’s a lot of special characters in one line…

And what is Unit?

4/10

Lua

1
print("Hello World")

Again, nice and simple. How it should be for such a simple task.

10/10

Go

1
2
3
4
5
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}

Mostly clean, but I dislike that I have to import a library just to print a string.

7/10

JavaScript

1
console.log("Hello World!")

Also pretty simple. But that would be a wrong impression of the language.

Wait until you learn about Closures and Promises. Oh, and hoisting. And ES6 vs. ES5. And standard vs. Airbnb styles for linting. typeof functionality. null vs. undefined. Yeah I don’t like JavaScript.

7/10

Erlang

1
2
3
4
-module(hello_world).
-compile(export_all).
hello() ->
io:format("Hello World!~n").

Uhhhh. Well, I guess Erlang is not usually the first language of choice for most programmers.

4/10

D

1
2
3
4
5
import std.stdio;
void main()
{
writeln("Hello World!");
}

Not bad. About as clean as Go, maybe just a bit cleaner.

7/10

Pascal

1
2
3
4
program Hello;
begin
writeln ('Hello World!');
end.

…actually, I like this. I really like this. The “begin” and “end” keywords are a nice touch.

7/10

Groovy

1
print “Hello World!”

Bout as simple as it gets.

10/10

Objective-C

1
2
3
4
5
6
7
8
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"Hello World!");
}
return 0;
}

Oh dear lord. Pointers, arrays, and memory management just to print a string?

What is an autoreleasepool?

What is “NSLog”? What does “NS” stand for? I can’t even muster a guess.

3/10

F#

1
printfn "Hello World!"

This is an angry print. It’s not just “print hello”, it’s “print f*ckin hello damn you”

8/10

Visual Basic

1
2
3
4
5
Module HelloWorld
Sub Main( )
System.Console.WriteLine("Hello World!")
End Sub
End Module

Not bad. Modules and “Sub” though? As in “subroutine”, like assembly language?

6/10

Speaking of…

MIPS Assembly

1
2
3
4
5
6
.data
output: .asciiz "Hello World!"
.text
main: li $v0, 4
la $a0, output
syscall li $v0, 10

…well, let’s just say I’m glad Java and Python exist.

1/10

Rust

1
2
3
fn main() {
println!("Hello World!");
}

Nice. Not as nice as a one-liner, but still extremely simple and easy to understand.

Little confused by the bang on println though. Earlier we had the angry printfn. Now it’s an excited println!

9/10

R

1
print("Hello World!")

Yep yep, nice.

10/10

Swift

1
2
3
import Swift

print("Hello World!")

Hahahaha I have to import the language before it can use itself??

7/10

Fortran

1
2
3
Program Hello
Print *, "Hello World!"
End Program Hello

Syntax seems simple, but the * is a little confusing.

And also, why 6 spaces before code begins? What the hell?

5/10

TypeScript

1
console.log("Hello World!")

Pretty simple and same as JavaScript. Guess TypeScript is supposed to be JavaScript’s better-dressed, more-spoiled younger brother.

8/10

Overall

Based on my arbitrary, non-serious opinions and ratings of the above, the ranking is as follows:

  1. Python (10/10), Groovy (10/10), R (10/10), Lua (10/10)
  2. Rust (9/10), Clojure (9/10)
  3. Perl (8/10), F# (8/10), TypeScript (8/10)
  4. JavaScript (7/10), Go (7/10), Swift (7/10), D (7/10), Pascal (7/10), Bash (7/10)
  5. Visual Basic (6/10), PHP (6/10)
  6. Ruby (5/10), C (5/10), C++ (5/10), Java (5/10), Fortran (5/10)
  7. Haskell (4/10), Scala (4/10), Erlang (4/10)
  8. Objective-C (3/10)
  9. C# (2/10)
  10. MIPS Assembly (1/10)

…let’s just say I won’t be learning MIPS any time soon.

Hope you enjoyed this stupid story. Happy coding!