172
\$\begingroup\$

The determined Real Programmer can write Fortran programs in any language.

from Real Programmers Don't Use Pascal

Your task is to write program in your programming language of choice, but you are allowed to use only another language. That is, throw away all coding conventions from one language and replace them with coding conventions from other language. The more the better. Make your program look as if it was written in another language.

For example, Python fan who hates Java could write following Python program in Java:

void my_function()                                                             {
    int i = 9                                                                  ;
    while(i>0)                                                                 {
        System.out.println("Hello!")                                           ;
        i = i - 1                                                              ;}}

Pascal enthusiast forced to use C could write this:

#define begin {
#define end }
#define then
#define writeln(str) puts(str)

if (i == 10) then
begin
    writeln("I hate C");
end

You have to write complete program. The program desn't have to do anything useful.

Good Luck. This is a popularity contest so the code with the most votes wins!

\$\endgroup\$
17
  • 1
    \$\begingroup\$ @m.buettner create your file with the extension .litcoffee. It might help. \$\endgroup\$ Commented Mar 20, 2014 at 22:53
  • \$\begingroup\$ A little long (and previously-written; and not self-contained) for an answer, but: Postscript scanner in Postscript in C. \$\endgroup\$ Commented Mar 21, 2014 at 4:36
  • 53
    \$\begingroup\$ I don't think you (or the majority of the answers) understand the point of the quote. It's not that a Real Programmer writes code that looks lexically like Fortran even though he's writing in Pascal or LISP: it's that he applies a Fortran way of thinking even when writing in Pascal or LISP; e.g. "As all Real Programmers know, the only useful data structure is the Array.". Great answers would be procedural code in Prolog, functional code in C, object-oriented code in Pascal. \$\endgroup\$ Commented Mar 21, 2014 at 11:10
  • 1
    \$\begingroup\$ I hope someone's gonna do a Lisp dialect in, well, anything but another Lisp dialect... \$\endgroup\$
    – itsjeyd
    Commented Mar 21, 2014 at 21:23
  • 7
    \$\begingroup\$ @itsjeyd Greenspun's Tenth Rule Of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp." \$\endgroup\$ Commented Mar 25, 2014 at 17:38

36 Answers 36

1
2
2
\$\begingroup\$

Ruby in JavaScript

Number.prototype.times = function(f){
  for (var i=this; --i;) f()
}
end = 0
function do(s) {return new Function(s)}

//;# Ruby starts here:
(5).times(do("alert('hi!'); end"))
\$\endgroup\$
1
  • 8
    \$\begingroup\$ Isn't this ruby in javascript? Not the other way around? \$\endgroup\$
    – Shelvacu
    Commented Mar 21, 2014 at 6:02
1
\$\begingroup\$

Asp in PHP

fskdfkz

Well I know, not very useful.

\$\endgroup\$
1
\$\begingroup\$

ALGOL in C

Steve Bourne already won this contest by writing the original sh in ALGOL in C.

#define IF      if(
#define THEN    ){
#define ELSE    } else {
#define ELIF    } else if (
#define FI      ;}

#define BEGIN   {
#define END     }
#define SWITCH  switch(
#define IN      ){
#define ENDSW   }
#define FOR     for(
#define WHILE   while(
#define DO      ){
#define OD      ;}
#define REP     do{
#define PER     }while(
#define DONE    );
#define LOOP    for(;;){
#define POOL    }

and

LOCAL VOID      gsort(from,to)
        STRING          from[], to[];
{
        INT             k, m, n;
        REG INT         i, j;

        IF (n=to-from)<=1 THEN return FI

        FOR j=1; j<=n; j*=2 DONE

        FOR m=2*j-1; m/=2;
        DO  k=n-m;
            FOR j=0; j=0; i-=m
                DO  REG STRING *fromi; fromi = &from[i];
                    IF cf(fromi[m],fromi[0])>0
                    THEN break;
                    ELSE STRING s; s=fromi[m]; fromi[m]=fromi[0]; fromi[0]=s;
                    FI
                OD
            OD
        OD
}
\$\endgroup\$
1
\$\begingroup\$

An operating system where all of the C is also valid Ruby: https://github.com/duckinator/corundum

To run as Ruby: ruby src/kernel.rb

To compile and run the operating system: make qemu

Output of both is Hello, world!\n

\$\endgroup\$
0
\$\begingroup\$

Commodore 64 Basic, BBC Basic etc.

Cheeky entry:

10 PRINT "HELLO WORLD"
20 GOTO 10
RUN

I did think about including Spectrum since you can type GOTO, but it renders GO TO, so technically not the same.

\$\endgroup\$
-6
\$\begingroup\$

HTML in PHP

First thing that came to my mind was apparently stolen by @toscho . But i'm not giving up yet,

<?php
echo "<title>This is HTML in PHP</title>";
echo "<p>Now Beat This!!!</p>";
echo "<br>";
?>
\$\endgroup\$
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.