Saturday, August 8, 2009

World's Smallest "Hello World" program

It's quite formal way to start with a "hello world!" program while introducing a new programming language. It is convinient by starting from "hello world" because the program may run properly and is helpful in gaining the confedence. Also it gives a proper output - Prints "hello world!" on the monitor. The programmer becomes happy while seeing this output. Here is a simple "hello world!" program in C.

#include
main()
{
printf("hello world!");
}
//output is
//hello world!


Quite simple?
But I think it is not at all simple. The special characters present in the program really offer some disturbances for the beginner, however a C program is not redundant and it is extreamly powerful.

In Python, I found a much more convenient way.

print "hello world!"


Simple?
It seems good but there is still void to shrink.

Take a look at Ruby,

"hello world"


That's it. I didn't found any void to shrink here. Just put the string you want to print in quotes (" ") and it is pretty easy. But this is not the standard way of printing a string on the monitor, as far as the offcial website of Ruby is concerned. They recommends,

puts ("hello world!)


Then the output will be,

Hello World
=> nil

nil stands for there is nothing to return.

4 comments:

Anonymous said...

You have already said that just 'hello world!' is not a valid method. Then what's the difference between ruby and python?
Dude, All scripting languages can have single line 'hello world'.

Tom Varghese Konikkara said...

Then what's the difference between ruby and python?
Reply:
Mr. Anonymous, I accept your argument. All scripting language has a single line hello world. But they can't shrink their line to as small as 'hello world!'. Just look this python code:

>>>def x():
... print "Hello World!"
>>>x() #Really small isn't it?
Hello World!

saju john said...

this / Puts / can also be used in C....

Tom Varghese Konikkara said...

Reply to Saju John
Yes, almost all programming languages copied something from C I think.