24 comments

[ 1.1 ms ] story [ 51.5 ms ] thread
Sad to see brainfuck missing :/
99 Bottles is a similar, if slightly more complex, thing. Brainfuck included!

http://www.99-bottles-of-beer.net/

But it has 1500 different programming languages, which is FAR more impressive (whitespace included =D)
99 Bottles is way better because it covers iteration. FizzBuzz is even better because 99 Bottles emphasizes string handling a bit much.
One of the more popular sites of this nature is rosettacode.org, which in their own words, "is a programming chrestomathy site. The idea is to present solutions to the same task in as many different languages as possible, to demonstrate how languages are similar and different, and to aid a person with a grounding in one approach to a problem in learning another."

For example: http://rosettacode.org/wiki/Hello_World

Plus, I enjoyed learning the word "chrestomathy", which "from the Greek words khrestos, useful, and mathein, to know, is a collection of choice literary passages, used especially as an aid in learning a subject."

Interestingly enough, I think this is the first time I see this word used in English, though in Russian it is pretty common (unsurprisingly, used in the same context). In fact, Google has 10 times more results for Russian one than for the English one.
The intention behind "Hello, world!" was to show the steps you need to run your code. In C's case: compiling it.

These examples just show some silly code, without any further information.

It would be really interesting to see how some languages deploy.

A bit off-topic, but the site locks up Chrome on Snow Leopard and causes one my cores to peak, and I'm forced to eventually kill the tab. Firefox has no problems. Any ideas why that might be?

Otherwise, a fun read-through.

JavaScript example is wrong:

  <a href="#" onclick="helloWorld(); return false;">Hello World Example</a>
none of the JavaScript ones even work in Node.js, I'd probably consider

    console.log('Hello, world!');
to be the closest to universal one.
(comment deleted)
Some implementations don't define console, so this wouldn't work in some (for example, Rhino).

Something like this would be more universal:

    if (typeof console === 'object') {
        console.log('Hello, World!');
    } else if (typeof document === 'object') {
        document.write('Hello, World!');
    } else {
        print('Hello, World!');
    }
http://progopedia.com/implementation/rhino/
god damn rhinoceruses fucking everything up.
Brainfuck was missing. Here is Hello World in brainfuck

    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]
    <.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.
PHP ones are wrong. Hello world in PHP is this:

Hello world!

Yup, people often miss that PHP is modal and that the default mode is simply to output. So if you put Hello World in a file it actually compiles to these opcodes:

    ECHO      'Hello+World%0A'
    RETURN    1
Which is identical to the opcodes produced by putting <?php echo "Hello World"; ?> into a file.
No, it's not identical.

    $ echo -n "<?php echo 'Hello World'; ?>" > hello.php
    $ php -d vld.active=1 -d vld.execute=0 -f hello.php
    line     # *  op                           fetch          ext  return  operands
    ---------------------------------------------------------------------------------
    1     0  >   ECHO                                                     'Hello+World'
          1    > RETURN                                                   1

    $ echo -n "Hello World" > hello.php
    $ php -d vld.active=1 -d vld.execute=0 -f hello.php
    1     0  >   ECHO                                                     'Hello+World'
          1    > RETURN                                                   1

    $ echo "<?php echo 'Hello World'; ?>" > hello.php 
    $ php -d vld.active=1 -d vld.execute=0 -f hello.php
    1     0  >   ECHO                                                     'Hello+World'
    2     1    > RETURN                                                   1

    $ echo "Hello World" > hello.php 
    $ php -d vld.active=1 -d vld.execute=0 -f hello.php
    2     0  >   ECHO                                                     'Hello+World%0A'
          1    > RETURN                                                   1
PHP 5.3.10-1ubuntu3.6 / Zend Engine v2.3.0 / vld-0.11.2
actually the code for ruby is even simpler:

"Hello world"

AS3 example creates class with a method but doesn't call the method. Also it subclasses a sprite but then uses trace (console log). Fractally bad.