Slashdot Mirror


Quadrilingual Crazy Programming

mtve writes: "Have you ever seen source code that is valid on four languages: Perl, C, Befunge, and BrainF*ck? During last Perlgolf season famous Perl hacker Jérôme Quelin submit such inconceivable masterpiece and now he published expanded explanation of his solution. Caution: that text can hurt your mental health. Play Perlgolf!"

22 of 194 comments (clear)

  1. Not for me... by PepsiProgrammer · · Score: 5, Funny

    I have enough trouble making my code compile in ONE language, 4 at the same time is a bit much

    --
    "The United States has no right, no desire, and no intention to impose our form of government on anyone else." - Bush 05
    1. Re:Not for me... by larry+bagina · · Score: 4, Funny
      I have enough trouble making my code compile in ONE language, 4 at the same time is a bit much

      Hi Linus. I didn't know you posted to Slashdot!

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

  2. omg... by Danse · · Score: 5, Funny

    He should seek professional help. Soon. That's right up there with self-mutilation.

    --
    It's not enough to bash in heads, you've got to bash in minds. - Captain Hammer
    1. Re:omg... by SkulkCU · · Score: 4, Funny


      He should seek professional help. Soon.

      at the bottom of the page:

      the referees were so impressed by my efforts (one of them told me that I deserve a book. And a straightjacket. And a padded room [...] they decided to grant me a book for my efforts.

      --
      .sig last updated Jan. 14, 2000
    2. Re:omg... by red_dragon · · Score: 4, Insightful
      Please, someone write a +5 insightful essay about why I shouldn't do this...before it's too late.

      I'm afraid that before someone writes such an essay, someone else will have written a +5 Funny post on why you *should* do it. Sorry.

      --
      In Soviet Russia, Jesus asks: "What Would You Do?"
  3. Wow, but slight dilemma by lkaos · · Score: 4, Funny

    Now this is exactly why I am proud to be a programmer. Screw Picaso and DaVinci, this is what real art is all about.

    This presents an interesting dilemma though. What Emacs mode do I use to look at the code??? perl-mode, c-mode, I dunno. Fontifying just complicates it even more.

    At any rate, this shit is going up in my cube. If they should this in a frame, I would buy it and hang it in my house.

    --
    int func(int a);
    func((b += 3, b));
  4. "Polyglot" did that 10 years ago! by Lardmonster · · Score: 4, Informative

    http://www-2.cs.cmu.edu/afs/cs/user/chogan/Web/pol yglot

    Cobol, Pascal, Fortran, C, Postscript, shellscript, 8086

    --
    The more advanced the technology, the more open it is to primitive attack
  5. How about 7 languages? by Zifter · · Score: 5, Informative
    What about the famous Polyglot?

    It runs/compiles under 7 languages: ANSI COBOL, ISO Pascal, ANSI Fortran, ANSI C, PostScript, Shell Script, and 8086 machine language!!! Check it out, it rocks.

    1. Re:How about 7 languages? by Internet+Ninja · · Score: 4, Informative

      The offical 'home' of polyglot is http://ideology.com.au/polyglot/.
      One of the authors was until recently my boss. While you're there have a good laugh and Corporate Hoore and Geocaching.

      BTW: polyglot has been mentioned here before.

  6. Code includes preprocessor directives by Sancho · · Score: 4, Interesting

    He uses the fact that # is a comment in Perl VERY frequently to use #defines etc that will allow C to act like Perl. Interesting solution, although I question whether the use of such preprocessor directives REALLY counts as making cross-compatible code. Then again, I nitpick the difference between preprocessor and compiler, so...

  7. simpler version by damiam · · Score: 4, Funny
    This program is valid in C, C++, python, perl, basic, and a few other languages, and it also accomplishes the rare feat of printing its own source code without reading from a file:





    Note that, even though this is standard C, gcc won't compile it, complaining about the lack of a "main" function.

    --
    It's hard to be religious when certain people are never incinerated by bolts of lightning.
  8. It's neat, but... by meta-monkey · · Score: 5, Insightful

    First off, this guy obviously has much better kung-fu than I do...I've never even heard of BrainFuck or Befunge...but I think he kinda cheated on the last two languages. He just hid the code for Brainfuck and Befunge in perl and C comments, so they wouldn't interfere with each other. Now, the perl/C part is really neat, because he used C #defines to translate various Perl characters into C, so the Perl interpreter and C compiler are reading and understanding the exact same code...that's cool. But the B & B code just gets ignored by the Perl interpreter and C compiler because of comments, so this amounts to writing 3 seperate programs (one in BrainFuck, one in Befunge, and one that's bi in C and Perl) and then putting them all in the same file with intstructions as to which compiler/interpreter reads which part, as opposed to writing one piece of code that's meaningful in all 4 languages. I'd call this bilingual, not quadlingual.

    --
    We don't have a state-run media we have a media-run state.
  9. Too Bad... by susano_otter · · Score: 5, Funny
    Have you ever seen source code that is valid on four languages: Perl, C, Befunge, and BrainF*ck? During last Perlgolf season famous Perl hacker Jérôme Quelin submit such inconceivable masterpiece and now he published expanded explanation of his solution. Caution: that text can hurt your mental health.

    Ironically, the article isn't even valid in one language.

    --

    Any sufficiently well-organized community is indistinguishable from Government.

  10. Befunge? by Quixote · · Score: 4, Funny
    From the article (yes, I read it, and yes, my jaw won't close now):
    Befunge is, ... a topological language on a 2D cartesian Lahey space.

    Holy mackerel! I am in love. I've found the object of my dreams.

    1. Re:Befunge? by PurpleBob · · Score: 4, Insightful

      Benefits? It's really fun to program in.

      Useful benefits? Does it need any?

      --
      Win dain a lotica, en vai tu ri silota
  11. Multilingual is the norm... by KFury · · Score: 4, Interesting

    ...on th web, anyhow. All the time we deal with several languages, burying one inside another so they'll make sense as they go through successive levels of parsing.

    For example, every day I write SQL that is buried in PHP libraries which extracts more PHP that in turn has HTML and Javascript in them.

    For another example of the crazyness, check this simple example. Now if you look at the source, you'll notice the end part of that A-tag was: .');"> For those of you who are counting, that's SIX 'enders' in three syntax languages just to form a simple alert box.

    . - English syntax
    ' - Javascript string syntax
    ) - Javascript function syntax
    ; - Javascript instruction syntax
    " - HTML attribute syntax
    > - XML (err, HTML, whichever) tag syntax

    And that's not even a particularly hairy example. That's just client-side and wetware-side parsing.

  12. I'm glad I'm already a programmer... by yorgasor · · Score: 4, Funny

    Wow, if I saw that a few years ago, I would've been so scared I would've never touched another programming language again! Slashdot, please think of the children before you post things like that.

    --
    Looking for a computer support specialist for your small business? Check out
  13. No, you're the one on drugs by yerricde · · Score: 4, Informative

    The correct term is tetralingual, not quadrilingual.

    "Quadri" comes from Latin. "Lingual" is from Latin. "Tetra" comes from Greek. In general, a compound will be all-Greek or all-Latin, with the occasional exception such as "homosexual".

    Quadrilingual is used in 1,210 pages, whereas tetralingual is used in only 14.

    I assume your Game Boy reference alluded to Tetris®. In that case, the existence of Quadra negates any "by default, go with the name of the block game" rule. In other words, you need to lay off the drugs ;-)

    --
    Will I retire or break 10K?
  14. just curious by Permission+Denied · · Score: 5, Interesting
    #define ARGV argv

    Why not just do this instead:

    main (int argc, char *ARGV[])

    Also, another minor quip: the C program is not valid C in either C89 or C99. It's not valid C89 because it uses '//' for a comment, and it's not valid C99 since it introduces main() without declaring the return type. C89 defaults to int if you don't declare the type (both for functions and variables, which can be fun), whereas this behaviour is undefined in C99. Normally, I don't follow the anal-retentive lingual purists, but I think this situation calls for this.

    But yeah, this is pretty cool.

  15. Re:Shouldn't this tell us something? by joto · · Score: 5, Informative
    This must be some of the worst bullshit I've heard about programming languages in quite some time.

    Did you even read the article. I'll challenge you to find languages with much more different syntax from C/Perl than Befunge-98 and Brainfuck!

    There used to be PASCAL for scientists, FORTRAN for mathematicians, BASIC for hobbyists or new programmers...

    Actually, Pascal was for education, (and systems-programming (once you added some much-needed non-standard extensions)). Fortran was for scientists (mathmaticians would probably be happier with Lisp, or something like Mathematica, only scientists needs actual numbers).

    Obj C, C, and C++ are very similar

    No, they are not. Well, ObjC and C are the most similar of the three, but modern C++ has little in common with idiomatic C. Java looks very similar to Objective C (which pretty much tells you how different C and Objective C are).

    ...and most of the new 'Basic' environments like REALBasic and VisualBasic are near clones as well.

    Maybe. My experience with VB didn't leave me thinking it was anything close to Java (or any other of the above mentioned languages). However, VB.NET is supposed to be so.

    All of today's popular coding environments could be condensed to Java, Objective C, Perl, and some form of BASIC.

    Well, if by popularity, you mean lots of users, or lots of jobs available, I am very confused why Objective C is on the list (although OS X should give it a boost). On the other hand, if you mean liked by it's users, you will hardly find any language not fitting that description. By any account, you need C++ on the list.

    But yes, I agree that such a list can be made, and mine would be: C, C++, Java, VB, Perl, COBOL, PL/SQL, HTML/XML, ASP/JSP/PHP, SAS, Python, Matlab, Fortran, Common Lisp, mostly in that order, but maybe COBOL even more to the front of the list.

    Anyway, there is no way to avoid C, C++ and or Java on the top of the list. (Which maybe was your point, but anyone taking more than a cursory glance at those languages will find that they are in fact very different from each other. They look similar on the surface, but are just as different as Pascal, Fortran and Basic).

  16. Editors, edit! by czth · · Score: 4, Insightful
    mtve writes: "Have you ever seen source code that is valid on four languages: Perl, C, Befunge, and BrainF*ck? During the last Perlgolf season famous Perl hacker Jérôme Quelin submitted one such inconceivable masterpiece and now he has published an expanded explanation of his solution. Caution: that text can hurt your mental health. Play Perlgolf!"

    Why is it that Slashdot's editors can't fix the mistakes in the above and many, many other articles before posting? Either they don't notice the errors (in which case they should be sacked and replaced), or it's that important to post the article a minute earlier (highly unlikely), or somehow the original wording is considered "sacred" and Not To Be Changed (stupid if true). Come on here. Does the error rate on the front page have to be so high?

    The only reason I'm not blaming the submitter (mtve) as well is because it's possible English is not his first language (or even his second). If it is, shame on him too. We all deserve better.

    (Oh yes, for those clueless enough to say "What errors", I threw in the required changes in bold. Also, isn't one Perlgolf link enough?)

    czth

  17. A Brainfuck Interpreter in PHP by the_danielsan · · Score: 4, Informative

    I wrote a Brainfuck interpreter in PHP a while ago which also includes a short introduction to the language.

    By the way, Brainfuck was initially named "Mental Masturbation", but the Author Oliver Müller then stuck to a less offensive name :)