Computer say hello

Computer say hello

Why does every programming language feel the need to re-locate the print function?

Here’s a summary of the top 20 programming languages' prints – as according to Github PR’s in 2021 Q1 and Rosetta Code’s Hello World solutions

For languages I haven’t used/seen much of I’ll take the top example, if I happen to know a more commonly used function I’ll include that as well.

  1. JavaScriptdocument.write("Hello world!"); or console.log("Hello world!")
  2. Pythonprint "Hello world!" or print("Hello world!") *
  3. JavaSystem.out.println("Hello world!");
  4. Gofmt.Println("Hello world!")
  5. Rubyputs "Hello world!"
  6. C++std::cout << "Hello world!" << std::endl;
  7. TypeScript – See Javascript
  8. PHPecho "Hello world!\n";
  9. C#System.Console.WriteLine("Hello world!");
  10. Cprintf("Hello world!\n"); or puts("Hello world!")
  11. Shellecho "Hello world!"
  12. Scalaprintln("Hello world!")
  13. Dartprint("Hello world!"); **
  14. Kotlinprintln("Hello world!")
  15. Rustprint!("Hello world!");
  16. Swiftprint("Hello world!")
  17. DMsrc << "Hello world!"
  18. Groovyprintln "Hello world!"
  19. Objective-CNSLog(@"Hello, World!");
  20. ElixirIO.puts "Hello world!"

* I’ll only be counting Python’s two print variants once, as it’s just different syntax.

** I don’t really know why the example on Rosetta code uses a variable, I haven’t personally tested this exact snippet but elsewhere it seems to be done.

It’s interesting to note that as we get further down the list we trend towards print(ln). Certainly the Java-lites (Scala, Kotlin, Groovy) have agreed to keep println, whereas the rest seem to prefer print.

Of these examples, only 3 require a ‘'literal’‘ newline to be specified – C/C++ being two of these.

In summary:

println   = 4
print     = 4 // including Rust's print!
puts      = 3
log       = 3 // JS, TS and Obj-C (it's close enought right?)
echo      = 2
<<        = 2
WriteLine = 1
printf    = 1
write     = 1

There’s obviously a number of flaws in my counts – why didn’t I include Go’s printf? Why did I include C’s puts? Why did i include Objective-C in the logs? In the end of the day this was just a bit of fun, maybe in the future I’ll write an actual script to automate the process but for now it is what it is ;)