Why does every programming language feel the need to re-locate the print
function?
Here’s a summary of the top 20 programming languages' print
s – 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.
document.write("Hello world!");
or console.log("Hello world!")
print "Hello world!"
or print("Hello world!")
*System.out.println("Hello world!");
fmt.Println("Hello world!")
puts "Hello world!"
std::cout << "Hello world!" << std::endl;
echo "Hello world!\n";
System.Console.WriteLine("Hello world!");
printf("Hello world!\n");
or puts("Hello world!")
echo "Hello world!"
println("Hello world!")
print("Hello world!");
**println("Hello world!")
print!("Hello world!");
print("Hello world!")
src << "Hello world!"
println "Hello world!"
NSLog(@"Hello, World!");
IO.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 ;)