News for hackers. Stuff that matters.
Re:Hello world in every programming language by rll on Sunday April 29, 2012 @04:34AM (#3905511)
Technically Hello World in PHP is just:

Hello World

The one they have with <?php print("Hello World"); ?> is also an opcode longer than using <?php echo "Hello World"; ?> because off the FREE on the return value from the print. But a file just containing the string: Hello World and nothing else will generate the same opcodes as the echo version so they are equivalent and you might as well use the shorter form. A file without an opening <?php tag is still a perfectly valid PHP program.

Re:Hello world in every programming language by lhnz on Sunday April 29, 2012 @08:19AM (#3905812)
Where do you learn such in depth information about PHP. The source code?
Re:Hello world in every programming language by rll on Sunday April 29, 2012 @10:47AM (#3906079)
It helps if you wrote a good chunk of it.

But one way that is easier than diving into the source code is to just dump the opcodes using vld (see pecl.vld). I have a little wrapper shell script /usr/local/bin/vld:

  #!/bin/sh -e
  exec php -dvld.active=1 -d vld.execute=0 "$@"
Then for the hello world program with the print() call:

  % vld hello1.php
  Finding entry points
  Branch analysis from position: 0
  Return found
  filename:       /tmp/hello1.php
  function name:  (null)
  number of ops:  3
  compiled vars:  none
  line     # *  op                           fetch            ext  return  operands
  ---------------------------------------------------------------------------------
     2     0  >   PRINT                                            ~0      'Hello+World'
           1      FREE                                                     ~0
     4     2    > RETURN                                                   1

  branch: #  0; line:     2-    4; sop:     0; eop:     2
  path #1: 0, 
vs. the one that just contains the string: Hello World

  % vld hello2.php
  Finding entry points
  Branch analysis from position: 0
  Return found
  filename:       /tmp/hello2.php
  function name:  (null)
  number of ops:  2
  compiled vars:  none
  line     # *  op                           fetch          ext  return  operands
  ---------------------------------------------------------------------------------
     2     0  >   ECHO                                                     'Hello+World%0A'
           1    > RETURN                                                   1

  branch: #  0; line:     2-    2; sop:     0; eop:     1
  path #1: 0,
Re:Hello world in every programming language by why-el on Sunday April 29, 2012 @11:37AM (#3906204)
Sorry to bother with an unrelated question, but how did you format the code pasted in your response?
Re:Hello world in every programming language by rll on Sunday April 29, 2012 @11:42AM (#3906219)
Re:Hello world in every programming language by why-el on Sunday April 29, 2012 @11:50AM (#3906240)
Thank you. I read that a while ago but I must have missed the section on code.
Re:Hello world in every programming language by mtrn on Sunday April 29, 2012 @03:45AM (#3905428)
While Hello World is nice, something a bit more involved could give you more insight. Among many people, Amit Singh (of MacFuse and Mac OS X Internals fame) did this with the Towers of Hanoi: http://www.kernelthread.com/projects/hanoi/ (111 Hanoi implementations total).
Re:Hello world in every programming language by objclxt on Sunday April 29, 2012 @04:26AM (#3905498)
One of my favourites is 99 Bottles, with just under 1,500 implementations: http://99-bottles-of-beer.net/abc.html - some are inspiring, but others are just plain funny.
Re:Hello world in every programming language by nrkn on Sunday April 29, 2012 @08:54PM (#3907596)
I manage a repo that has the bare bones of a roguelike in many languages.

It's a little more involved than a Hello World in that it needs to handle input, output, state etc.

I could always use more languages if anybody wants to pitch in.

https://github.com/nrkn/SimpleRL

Re:Hello world in every programming language by baddox on Sunday April 29, 2012 @07:12AM (#3905701)
The Rosetta Code is a much more interesting and useful site along the same lines.

http://rosettacode.org/wiki/Rosetta_Code

Re:Hello world in every programming language by gtani on Sunday April 29, 2012 @09:44AM (#3905951)
There's probably a lot more cheats and cookbooks, but:

http://pleac.sourceforge.net/

http://hyperpolyglot.org/

Re:Hello world in every programming language by doktrin on Sunday April 29, 2012 @03:50AM (#3905439)
Why is Morse code included? I'm not being flippant, but rather genuinely curious as to whether there's some basis for it being considered a "programming" language or precursor thereof.

This isn't to confuse Morse code with reMorse : http://esolangs.org/wiki/ReMorse

Re:Hello world in every programming language by mtrn on Sunday April 29, 2012 @04:32AM (#3905508)
I started to read Code: The Hidden Language of Computer Hardware and Software by Charles Petzold two days ago - and he starts with morse code (and braille). You're right, it's no programming language (just an encoding) - but seemingly near conceptually to a language (for Petzold, anyway - yay it's got 0's and 1's, too).
Re:Hello world in every programming language by pmjordan on Sunday April 29, 2012 @07:38AM (#3905742)
Does the book really focus on Morse code having 0s and 1s? Isn't it technically a ternary encoding as opposed to a binary (0/1) one? The gaps between letters are pretty significant.
Re:Hello world in every programming language by mkopinsky on Sunday April 29, 2012 @09:49AM (#3905958)
This is what I found funny about Gmail Tap 28 days ago. They managed to take Morse Code - a tertiary encoding with only one input button - and "simplify" it by having three buttons.
Re:Hello world in every programming language by cloudwalking on Sunday April 29, 2012 @05:18PM (#3907163)
We simplified the default Android keyboard from ~28 keys to 3. We didn't simplify Morse Code.
Re:Hello world in every programming language by mkopinsky on Sunday April 29, 2012 @06:53PM (#3907374)
You complexified Morse code, is the point! Once you're doing Morse code, you may as well make the entire keyboard be one key!
Re:Hello world in every programming language by rikthevik on Sunday April 29, 2012 @03:02PM (#3906682)
Turing completeness is a pretty good indicator of whether you're looking at a programming language or not.
Re:Hello world in every programming language by Groxx on Sunday April 29, 2012 @04:03AM (#3905457)
Another very large set of hello worlds: http://rosettacode.org/wiki/Hello_world
Re:Hello world in every programming language by ushi on Sunday April 29, 2012 @08:33AM (#3905835)
This repo is out of date. There are 9 months old pull requests open. Here is a fork: https://github.com/c00kiemon5ter/hello-world
Re:Hello world in every programming language by luzon on Sunday April 29, 2012 @04:08AM (#3905468)
node.js is not a programming language.
Re:Hello world in every programming language by furyofantares on Sunday April 29, 2012 @11:42AM (#3906215)
'Hello World' is not possible in javascript without support from whatever hosts it. The language itself has no support for input or output.

The site does have one filed only under 'javascript' implemented with alert(), but that's really javascript as it exists in browsers.

Re:Hello world in every programming language by eurleif on Sunday April 29, 2012 @05:28PM (#3907187)
You could say the same about C. Sure, the C standard library is specified along with the language, but it's still a library, not a set of language features. You could have C without the stdlib. So does that mean an example in C with an alternative IO library would be ok, but not a similar example in Python?

I don't think whether IO is built into a language is really the important question. If people are interested in seeing how IO works with different frameworks, those examples should be there. But if people just want to see what a language's basic syntax looks like, not the specifics of emitting IO in various frameworks, there should be one example per language, even for languages which lack built-in IO.

Re:Hello world in every programming language by aoprisan on Sunday April 29, 2012 @11:24AM (#3906178)
seriously, what's next? Hello World in all PHP frameworks?
Re:Hello world in every programming language by scriptproof on Sunday April 29, 2012 @08:18AM (#3905809)
One page list, more languages: http://www.scriptol.com/programming/hello-world.php (and older)
Re:Hello world in every programming language by reitzensteinm on Sunday April 29, 2012 @08:22AM (#3905817)
I remember reading that the Malbolge author was 'working' on a Hello World program, and thought that was awesome. Now I see why:

https://github.com/leachim6/hello-world/blob/master/m/malbol...

I wonder if it was written by hand; that would be impressive. Doesn't look like it would be too hard to hand roll a little compiler for it.

Re:Hello world in every programming language by tomjen3 on Sunday April 29, 2012 @08:37AM (#3905843)
At least the first one wasn't made by hand. It was created by a stochastic beam search program written it Common Lisp.

And if I recall correctly, it took years to do.

Re:Hello world in every programming language by reitzensteinm on Sunday April 29, 2012 @09:04AM (#3905892)
OK, rereading the specs, I completely take back what I said about handrolling a compiler not being difficult. Damn.
Re:Hello world in every programming language by shalmanese on Sunday April 29, 2012 @08:33AM (#3905836)
It was created using a genetic algorithm IIRC.
Re:Hello world in every programming language by chris_wot on Sunday April 29, 2012 @11:04AM (#3906132)
I think my head just exploded.
Re:Hello world in every programming language by jfoutz on Sunday April 29, 2012 @12:31PM (#3906320)
Re:Hello world in every programming language by joshbaptiste on Sunday April 29, 2012 @11:31AM (#3906191)
I prefer the FizzBuzz examples as it also displays the simple looping constructs of the languages http://rosettacode.org/wiki/FizzBuzz

Edit: Grr it is missing one of my favorite JVM.next() languages of the week Kotlin, I will have to update it.

Re:Hello world in every programming language by quink on Sunday April 29, 2012 @04:48AM (#3905527)
MUMPS was left out. Like usual :P

w "Hello World",!

Re:Hello world in every programming language by chris_wot on Sunday April 29, 2012 @06:25AM (#3905639)
Everything I've ever heard about MUMPS says that it's awful. Is this true?
Re:Hello world in every programming language by btwrto on Sunday April 29, 2012 @11:32AM (#3906194)
It's a language that predates C. Maybe some the things that you take for granted are not there, and some syntax is weird, and order of evaluation is strict left-to-right. (i.e. "'x+1=2+3" first computes 'not x', i.e. 0 or 1 if x=1 or x=0 respectively, then adds 1 to the result, then compares that result to 2, then adds 3 to that result, giving either 3 or 4 as a final answer).

but if you write controlled, sensible code, then it's actually not. certainly never my language of choice but it it's not just still used due to inertia... it's pretty fast, it makes database interaction easy, it's pretty easy to understand if the code isn't doing something awful like assuming variables and relying on hidden state. (which you can do, yes.)

if you're talking about the Daily WTF articles, then no it's not nearly as bad as those articles would imply. I worked for a company that is probably featured in one, but not all, of those articles... we had good tools, good coding standards/dev process, a good internal API/libraries that do quite a lot, and sensible people. Under these circumstances it was not bad--I'd actually grown quite fond of it. (No codebase of a large old company will be WTF-free but this isn't language-specific. I don't think any actual code from those Daily WTF articles actually comes from that company...)

Also, "A Case of the MUMPS" gets many things wrong.

'Scope of IF and FOR is "remainder of current line."' Nope. That's what 'do' is for. Note that ';' comments out everything to the right on the same line.

    for i=1:1:100 do  ; equivalent to 'for(int i=1;i<101; i++) { }', with the lines below indented with a period serving as the body of the brackets  
    . write !,"line 1 of code block, iteration "_i
    . write !,"line 2 of code block, iteration "_i
    . write !,"line 3 of code block, iteration "_i
    write !,"Done with loop" ; this gets executed after the for loop
Note that I'd actually write this as 'f i=1:1:100 d' and 'w "string"' in place of "for i=1:1:100 do" and 'write "string"'. It's just as easy to read if you know the language, especially if you have nice syntax highlighting, and easier to write. Which brings me to...

'To edit the code stored in the “database”, developers needed to use the internally-created text editor.'

Not in our case, and this makes me wonder how long ago this guy's experience was. in our case, the vendor provided an IDE and we also had our own, written in C#, which is actually my favorite IDE from any language.

Re:Hello world in every programming language by quink on Sunday April 29, 2012 @06:23PM (#3907314)
I can't think of a more usable productive language from the 60s that still survives. It's got a lower barrier of entry than C, and it's miles better than BASIC. It's more friendly than BASIC in fact, while still being faster, and is way more accessible than FORTRAN or COBOL.

You want to do FizzBuzz? I present the shortest FizzBuzz in almost any language other than APL or Perl:

  f i=1:1:100 w ! w:'(i#3) "Fizz" w:'(i#5) "Buzz" w:'$x i
Or, in pseudocode:

  for i=1:1:100
   print "\n"
   if not (i%3) print "Fizz"
   if not (i%5) print "Buzz"
   if not x_pos_of_cursor print i
Ah, yes, and don't ever use dot notation as above if you plan on wanting comments on your line, i.e.

  for 
   . blah
   ; some comment here
   . foo
foo here won't execute. Instead this works:

  for 
   . blah
   . ; some comment here
   . foo
Tripped me up the first time I dealt with that... however, these days with Caché ObjectScript (the most popular MUMPS dialect) it'd be written:

  for {
    blah
    // some comment here
    foo
  }
Re:Hello world in every programming language by drucken on Sunday April 29, 2012 @07:13AM (#3905705)
Largest collection "Hello world" in programming languages (441 at last count): http://www.roesler-ac.de/wolfram/hello.htm

It even has BCPL and LabVIEW!

Re:Hello world in every programming language by franze on Sunday April 29, 2012 @11:28AM (#3906183)
well, certainly not every programming language.

i.e.: i'm one of the most senior ACT3 programmers worldwide. (well, there were only about a dozen or so people) it was a programming language used extensively at the national austria press agency. it was - at it's time (around 2001) - for more advanced as PHP 4. the hello world would have looked something like this

<!--%'hello world'-->

(the <!-- --> was a relict from ACT2 ...)

yes it was an abomination, but it worked, and it was fast.

ok, anyway, ARC is missing, too. I think the claim "every programming language" is a) wrong and b) not really feasible.

Re:Hello world in every programming language by bmelton on Sunday April 29, 2012 @12:02PM (#3906262)
It's a work in progress, with the goal of getting every programming language in there.

Submit a pull request for ACT3 and you'll have one less language's absence to notice.

Re:Hello world in every programming language by albertzeyer on Sunday April 29, 2012 @12:29PM (#3906317)
"every programming language" is an infinite set. Every programming language where an interpreter/compiler was implemented once is maybe better. But, when you consider that most programmers have at one point invented their own language, or languages (I cannot really count how much toy languages I have created at some point), it is still way too much and impossible to get them all. Maybe more restrictive would be to take languages which at least 2 people have used at one point. But even then...

The point I'm trying to make is: "Every programming language" will always be wrong.

Re:Hello world in every programming language by franze on Sunday April 29, 2012 @12:14PM (#3906285)
will do. still "every programming language" - it's not really feasible.

does anyone know how many company/cooperation internal programming language are supposed to exist? is there even a way to estimate it?

Re:Hello world in every programming language by jiganet on Sunday April 29, 2012 @11:03AM (#3906128)
Hello world in PostScript:

/Times-Roman findfont 12 scalefont newpath 200 200 moveto (Hello World) show closepath Showpage

Use this in gs on Linux or y gswin32 on windows

Re:Hello world in every programming language by simonbarker87 on Sunday April 29, 2012 @07:16AM (#3905716)
LabVIEW is missing - can git support it?

Update:

And I don't see Processing either

Re:Hello world in every programming language by tzaman on Sunday April 29, 2012 @04:18AM (#3905486)
Not very useful
Re:Hello world in every programming language by tome on Sunday April 29, 2012 @08:07AM (#3905789)
The Python 3 version works in Python 2 as well. They may as well unify them.
Re:Hello world in every programming language by BasDirks on Sunday April 29, 2012 @08:00AM (#3905776)
I am not quite sure why the Haskell program needs a module statement.
Re:Hello world in every programming language by asjo on Sunday April 29, 2012 @05:09AM (#3905560)
COMAL 80 is missing. Too bad I don't remember anything of it :-)
Re:Hello world in every programming language by trin_ on Sunday April 29, 2012 @07:46AM (#3905757)
im not sure but that should just be:

10 PRINT "Hello World"

Re:Hello world in every programming language by knowtheory on Sunday April 29, 2012 @08:44AM (#3905858)
of course, it doesn't explain how to build and/or run any of them :P
Re:Hello world in every programming language by erode on Sunday April 29, 2012 @03:57AM (#3905449)
Missing F#.

printfn "Hello World"

Re:Hello world in every programming language by evincarofautumn on Sunday April 29, 2012 @04:08AM (#3905467)
Submit a pull request.
Re:Hello world in every programming language by silvestrov on Sunday April 29, 2012 @08:42AM (#3905855)
Missing too an example written in RPG: http://en.wikipedia.org/wiki/IBM_RPG

I'm not going to submit a pull request, fortunately I've never had to write anything in that language.

Re:Hello world in every programming language by evincarofautumn on Sunday April 29, 2012 @01:48PM (#3906497)
A friend of mine had a course in RPG in his CS curriculum. He tells me it was…not pleasant, but not as bad as it might look.
Re:Hello world in every programming language by goggles99 on Sunday April 29, 2012 @05:06PM (#3907123)
Where is the PL/I?
Re:Hello world in every programming language by zackzackzack on Sunday April 29, 2012 @10:36AM (#3906051)
I note a suspicious lack of DCPU-16.
Re:Hello world in every programming language by jabr on Sunday April 29, 2012 @05:29PM (#3907190)
There's an implementation in the pull request queue.
Re:Hello world in every programming language by jfoutz on Sunday April 29, 2012 @01:13PM (#3906401)
Has I/O been pinned down?