Quadrilingual Crazy Programming 196
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!"
Not for me... (Score:5, Funny)
Re:Not for me... (Score:4, Funny)
Hi Linus. I didn't know you posted to Slashdot!
How about dialects? (Score:2)
Re:Not for me... (Score:1)
Not for MS, though ... (Score:2)
According to Microsoft, their "Visual Studio" will do 5 languages at the same time !
omg... (Score:5, Funny)
He should seek professional help. Soon. That's right up there with self-mutilation.
Re:omg... (Score:1)
Not nearly as much fun though.
Re:omg... (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.
Re:omg... (Score:1)
Re:omg... (Score:4, Insightful)
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.
Wow, but slight dilemma (Score:4, Funny)
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.
It depends on the file extension you give it... (Score:2)
If you rename the file to quadlang.c or quadlang.cpp, then open it as c/c++. If you rename it to quadland.cgi, open it as perl, and so on. That's assuming you're going to rename it before sending it to any compiler.
Of course, that's just another problem with multiple languages per source file - figuring precisely how to name the file.
:^)
Ryan Fenton
Re:Wow, but slight dilemma (Score:1)
Re:Wow, but slight dilemma (Score:2, Informative)
No problem, just use vi(m)! In vim, you can use several colour-coding styles in one document. Just needs a bit of tweaking, that's all.
Re:Wow, but slight dilemma (Score:2)
I think there is just as much beauty in code as in many works of art.
Mozart is famous for his table top pieces. These are pieces where two muscians sat on opposite ends of a table with a piece of sheet music in the middle. The first piece played the piece right side up, and the second played the piece upside down. His genius was being able to create with such incredible restrictions.
Solving a problem in multiple languages represents a similiar ability. Of course, it wasn't a terribly complicated problem, but the basic idea is the same.
"Polyglot" did that 10 years ago! (Score:4, Informative)
Cobol, Pascal, Fortran, C, Postscript, shellscript, 8086
Re:"Polyglot" did that 10 years ago! (Score:1)
Re:"Polyglot" did that 10 years ago! (Score:1)
Yeah - that's really queer. There was no space in the textarea widget, but it was there in the preview.
So I typed it again, and again the space appeared.
Maybe something to do with Opera??
Re:"Polyglot" did that 10 years ago! (Score:1, Informative)
Polyglot is just a hello world (Score:1)
Moreover, all of polyglot's languages are languages that people have actually used to write real code. I'm not saying they are all reasonable languages, but one can at least semi-plausibly claim that they were written to be useful. Befunge and BrainF*ck are both toy languages written expressly to be perverse in some way (Befunge to be uncompilable, and BrainF*ck to be absurdly minimalist.)
That said, I was disappointed at how separate the languages' code blocks were in Quilen's program. C and perl share most of the same code, but there are three completely separate code blocks and the work is mostly in getting each language to ignore the others' code. It's probably the only way it can be done, but it's really a short quadralingual wrapper around three separate programs, one of which is bilingual.
Re:"Polyglot" did that 10 years ago! (Score:3, Interesting)
On the other hand, it's really, really cool.. How about a contest? Write a program that does a particular thing (dunno, calculate something (like Pi)), and should be compilable/runnable in a lot of languages. You get points from a jury from how good the program solved the task, times number of languages it is written in. Could be quite fun. (-8
Shouldn't this tell us something? (Score:1, Insightful)
Nowadays, Perl and PHP are almost identical, Obj C, C, and C++ are very similar, Java bears many similarities to Obj C and C++ as well, and most of the new 'Basic' environments like REALBasic and VisualBasic are near clones as well.
All of today's popular coding environments could be condensed to Java, Objective C, Perl, and some form of BASIC. This point is exemplified nicely by the fact that a bit of code can be done to compile in 4 languages... the syntax is already quite close, having so many minor variants is just messy.
Re:Shouldn't this tell us something? (Score:1)
each server
Either that, or its a typo...
Re:Shouldn't this tell us something? (Score:2)
This is an excerpt of the Befunge part:
> 2ep 1ep
v pe30 < a
And this is an excerpt of the BrainF*ck part (a language with 8 instructions):
>+>+<<<<<-]>>,--------- ---
And keep in mind that the actual program is much longer than that.
I wish I could include more, but the lameness filter won't allow me to...
So much for nearly identical languages...
Re:Shouldn't this tell us something? (Score:2)
[parent's parent] All of today's popular coding environments could be condensed to...
BrainFuck and Befunge are designed to be different, and more importantly, unintelligable. There are a million different languages out there (for example, Lisp looks nothing like Java) but the popular ones (not counting Lisp) all stem from either C or Basic.
Re:Shouldn't this tell us something? (Score:2, Informative)
PHP borrows its syntax from various other languages, including Perl, but also C, Java, Javascript, etc
Re:Shouldn't this tell us something? (Score:5, Informative)
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).
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).
Re:Shouldn't this tell us something? (Score:1)
The impression I got from VB was that it was sort of a bastardized combination of HyperCard, JavaScript and Q-BASIC all wrapped into one - the GUI concepts from HyperCard, the concept of objects and properties from JavaScript, and the syntax and vocabulary from Q-BASIC.
Note that the HyperTalk language is actually designed to be used in that kind of GUI environment, and is probably the highest-level language I've ever heard of (that's not to say it doesn't have shortcomings, like the lack of intangible objects, the awkwardness of storing arrays as text, inability to handle strings over 32k or containing nulls, and other issues I've forgotten about). Q-BASIC is absolutely not designed for this sort of thing at all, and is really not appropriate for working with objects. And JavaScript is a PITA all the way around.
Re:Shouldn't this tell us something? (Score:2, Interesting)
Malbolge. See these notes on writing hello, world in malbolge [acooke.org]:
this malbolge program generates:
HEllO WORld
it's not perfect - i ignored case to make the problem simpler (completion left as an exercise for the reader - it should be possible).
when i finally got a decent algorithm worked out (i've been playing around with this for the best part of a month - see below), it took a few hours to generate the program on a 500mhz nt box with 96mb memory (the code was written in lisp - i started with clisp on suse linux and then changed to corman lisp on nt) (more numbers here).
incidentally, i've come to hate malbolge.
Re:Shouldn't this tell us something? (Score:1)
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.
Functional languages are sorely under-represented in your list. It ought to include at least some dialect of ML (SML or O'Caml) and at least one pure functional language (e.g. Haskell). Really, though, it is a silly academic exercise to try to form a list that comprehensively includes every ``useful'' language, as definitions of useful vary widely. (In fact, that's why there are so many languages in the first place, and in some sense, why it's justifiable to have so many languages.)
Case in point: your list leans heavily towards the imperative and object-oriented styles of programming (C, C++, Java, COBOL, Perl, Python, Fortran), and also towards web technologies and scripting languages (HTML/XML, ASP/JSP/PHP (which are really three different things anyhow), Perl, Python, Java (arguably)). (It's also arguable that you include some languages which are decidedly less useful -- e.g. VB, SAS -- but i only mention that to point out that these things are all a matter of taste; let's not get into a holy war on everyone's favorite programming language! :)
Re:Shouldn't this tell us something? (Score:2)
Also, web-technologies are important in the real-world. To the point where I am almost surely convinced that one day, 90% of us will all work on web-infrastructure for each other, while the remaining 10% will take care of the rest of society.
Also, I was not trying to put together a list of useful languages. If a was, then my list would look entirely different. I was trying to list "popular" languages, for a suitable definition of "popular". I am very aware of the fact that just because something is "popular" and "much used" doesn't make it useful. And I am aware of functional languages, and do consider some of them to be useful. That doesn't make them "popular" though.
It might be that I was trying too much to remove my own bias from academia, and smart, well-educated programmers, but I don't really think so. Much of the real world revolves around the silliest programming languages.
Re:Shouldn't this tell us something? (Score:1)
Obligatory polyglot programming link (Score:3, Informative)
Everything2 entry on polyglots [everything2.com]
How about 7 languages? (Score:5, Informative)
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.
Re:How about 7 languages? (Score:4, Informative)
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 [slashdot.org].
Code includes preprocessor directives (Score:4, Interesting)
Re:Code includes preprocessor directives (Score:2)
Portable (Score:2, Funny)
simpler version (Score:4, Funny)
Note that, even though this is standard C, gcc won't compile it, complaining about the lack of a "main" function.
Re:simpler version (Score:1)
at some point.
I don't thikn the moderators are there,
or else it'd be 5, funny
ac karma whoring (Score:1, Informative)
It's neat, but... (Score:5, Insightful)
Re:It's neat, but... (Score:2)
#include can't be used because i is a valid instruction, so you have to use #undef. The reason why this is quadlingual is because you are able to run it through any of the 4 compilers/interpreters and get the same result. I could see the Perl and C working together without much difficulty, but when I read Brainfuck I was completely stumped how he would manage to do that. I think it's a very elegant solution. If by elegance, I mean insane and beautiful in a sick and twisted way. Just because the code gets ignored by the C/Perl interpreter doesn't make it any less bilingual. The code also gets ignored by the aidbf and b98 interpreters as well.
Too Bad... (Score:5, Funny)
Ironically, the article isn't even valid in one language.
Re:Too Bad... (Score:1)
not quite as cool as it sounds. (Score:2, Insightful)
Re:not quite as cool as it sounds. (Score:2, Funny)
What?!? Eliminate redundant logic? That would put microsoft out of business!
MacOS ~ Windows
Java ~ C#
Diablo ~ Dungeon Siege
Re:not quite as cool as it sounds. (Score:2)
Re:not quite as cool as it sounds. (Score:2)
My point? Just because you've seen the slight of hand behind the magic doesn't make the feat any less impressive. I mean seriously, how'd you expect him to accomplish this? : )
Befunge? (Score:4, Funny)
Befunge is,
Holy mackerel! I am in love. I've found the object of my dreams.
Re:Befunge? (Score:1)
"Hol[e]y rusted metal, Batman!"
Yes, I'm offtopic again. Mod me down.
Actually, Befunge looks like a lot more work than traditional procedural languages. What actual benefits does it offer? (Apart from "I can think in a language that causes your brain pain!")
Re:Befunge? (Score:4, Insightful)
Useful benefits? Does it need any?
Multilingual is the norm... (Score:4, Interesting)
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 [fury.com]. Now if you look at the source, you'll notice the end part of that A-tag was:
' - Javascript string syntax
) - Javascript function 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.
Re:Multilingual is the norm... (Score:1)
Re:Multilingual is the norm... (Score:2)
HTML+DOM+JS is great for e-brochures, but crappy and messy for complex business forms.
Even if you don't like SCGUI, at least promote something along the same lines. Trying to make web pages act like VB/Delphi/Powerbuilder is a royal micromanaging pain that is almost as as much joy as using Brianf*ck.
BTW, if you use ColdFusion, it has two language modes/syntaxes. Thus, you may end up using Coldfusion 1, Coldfusion 2, SQL, HTML, and JavaScript. 5 languages to get the job done.
Re:Multilingual is the norm... (Score:1)
I'm glad I'm already a programmer... (Score:4, Funny)
Re:I'm glad I'm already a programmer... (Score:2)
Just seeing people do some beautiful and crazy twists of logic inspired me on so many levels. I still remember the first piece of obfuscated code I got my hands on was this great Hello World program. Another one was a console animation that displayed an ASCII movie of a McDonalds delivery truck running a cow over then throwing the carcass into the back of the truck and driving off.
Sadly enough, those two programs inspired me to code more than anything to date. More sad, I've never entered an obfuscated code contest. I find myself more intruiged by finding elegant twists of logic that look pretty, and functional
Wishlist (Score:1)
I multi-program.... (Score:2, Insightful)
just curious (Score:5, Interesting)
Why not just do this instead:
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.
Re:just curious (Score:2)
Yeah, many people don't think about that. When I write C code I always write:
Some weird habit I picked up but it drives people nuts.. "hey, is that legal in C?", etc.Re:just curious (Score:2)
int main( int argc, char** argv);
My first CS teacher did that, and I objected and had to pull the reference. I see char** argv all the time, and can never figure out why it bothers me but it does. It's similar to misspelling definately[sic] -- no reason, just irritating.
5 languages (Score:2)
This article is a gem. (Score:3, Interesting)
I discovered BrainFuck by chance two years ago and immediately got lost in two nights of trying to get my first quine to compile in the interactive JavaScript BF interpreter. For some perverse reason it is fun. It brings out the little boy in me who used to build model airplanes out of toothpicks: Little unimportant things that become something when you stick them together. perhaps this would also be a possible real world language for programming Nanobots, whose processors wouldn't yet cope with a P4 strapped to their backs.
BrainFuck Nanobots? (Score:3, Funny)
News Reporter: So how'd you do it?
Guy: Well, the nanotech was already there. I just wrote a small program in BrainFuck in order to hunt down the virus.
Well, at least censorship would go out the window the same time we cure World Disease.
4 Languages? Whoopty doo. (Score:3, Funny)
That's an impressive feat?
Netscape 4.X = Worst browser ever!
Re:4 Languages? Whoopty doo. (Score:1, Offtopic)
Re:4 Languages? Whoopty doo. (Score:2)
if(!isNaN(parseInt(window.innerWidth))) {
pageWidth=parseInt(window.innerWidth);
} else {
if(!isNaN(parseInt(document.body.clientWidth))) {
pageWidth=parseInt(document.body.clientWidth);
} else {
pageWidth=700;
}
}
Falling back on a default if neither works.
Does someone have a better suggestion?
Re:4 Languages? Whoopty doo. (Score:2)
Yes, I said "no valid reason", and I mean it. I know some of you will give "presenting a uniform corporate image" as a reason. But it still won't be valid unless the corporate image you want to present is "style over substance".
Re:4 Languages? Whoopty doo. (Score:1)
Re:4 Languages? Whoopty doo. (Score:3, Funny)
"Your browser identifies itself as Internet Explorer 5.5 running on Windows XP. But it's really Konqzilla. I don't know why you want to see our site using Konqzilla. Please use a modern browser to view this site. Now go away."
"It appears that you're running Internet Explorer 5.5 running on Windows XP. And it's the real thing this time. But you're running it under WineX. Do you think we're stupid. We don't want you to view our site. Now bugger off!"
"Ah, a genuine Internet Explorer 5.5 running on a genuine Windows XP! Congratulations. But you have your monitor temperature set to 5000! Our site was designed for 9300. It will look fugly without it. Please correct the situation before returning"
And they call ME crazy... (Score:2)
where's my O'Reilly book? (Score:2, Troll)
I don't know if there's an official term for it, but I often write a function in one language that writes code for another language - for example, using PHP or Perl to write javascript. I've even gone so far as to use PHP to write a SQL statement which in turn is used to determine what will go in a Javascript function that writes HTML code. The example below is rather pointless, but I have come across real situations where it is beneficial to use that many languages together.
That's three "real" languages and one markup language. And if you think that was crazy, think about this - I just had to write that in HTML in a slashdot posting textbox!
My next goal is to make the javascript write out HTML for parameters in a Java applet. And, the whole PHP page is going to be written by a C program exectuted by a cron job that was set up via a perl script (webmin!) That's eight different languages - perl -> bash (I think) -> C -> PHP -> SQL and Javascript -> HTML -> Java. Sadly, I don't think that's nearly as crazy as the quadrilingual program. I need to learn Brainf*ck.
Re:where's my O'Reilly book? (Score:1)
Hey, that is MY password!
You copied it, you dipsh*t hacker you! FBI cometh.
Even more interesting if .... (Score:2)
How may languages is that understood in?
Re:Even more interesting if .... (Score:2, Insightful)
Slight nit-pick
However, it can be assumed that a fair number of people in the Japanese speaking (and signing) world have had to communicate with the western world, and they know that perticular hand guesture may not be taken well
Genetic algorithm (Score:2)
Turn it into a screen-saver ala Seti style, and maybe
Esoteric language challenge (Score:3)
I was happy to solve 1840, even though I immediately recognized the language, because it is poorly specified and there is no interpreter. But that was nothing compared with my teammates, who solved 1183 with nothing but the problem and pure reason.
not valid c (Score:1, Interesting)
Big deal. (Score:2)
Same with x86 machine code that is clever enough to determine if it's running inside of linux or windows... even though the code itself is valid, the elf vs.
Editors, edit! (Score:4, Insightful)
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
Re:Editors, edit! (Score:1)
My goodness (Score:1)
However, I'd like to see more difficult languages. Has anyone done LISP? Has anyone even ATTEMPTED Haskell or ML?
Now THIS is what slashdot is all about.! (Score:3)
Re:Now THIS is what slashdot is all about.! (Score:2)
Perl Coders (Score:1)
Polyglots... (Score:1)
polyglots list [nyx.net]
A Brainfuck Interpreter in PHP (Score:4, Informative)
I wrote a Brainfuck interpreter in PHP [lorch.cc] a while ago which also includes a short introduction [lorch.cc] 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 :)
Something for all compilers (Score:2)
-- Begin Code snippit beneath this line ---
-- End Code snippit above this line ---
Try it, it should work. You see, the key to getting it to work for everything out there is to compromise what the program can do.
Fortunately, since the goal was to make the program run in as many languages as possible, I can make the code as minimalistic as possible, too!
By the way, the code I mentioned above is property of myself. This code cannot be used in programs without my expressed permission. Doing so would be a violation of the terms in which I am distributing the above code.
Licensing agreements are available. Contact me for more info.
Cease and Desist Warning. (Score:3, Funny)
Poster named Damiam, you are in violation of the terms of my license. You are hereby asked to cease and desist from distributing your code, and will be contacted shortly with a cease and desist letter saying the same message.
If you do not pay royalties to me, I shall strip you of all your Karma, and fart in your general direction. :)
By the way, if you claim prior art, this is not true. I came up with this program back in 1984 when I was banging enter on the keyboard of my Commodore Pet computer and realized that I was programming it without my knowledge.
Re:Whoa... (Score:2)
Re:Whoa... (Score:2)
Nope.... Once it's compiled, it's all CPU instructions anyway...
Tim
Re:Whoa... (Score:1)
Re:LOL, the tradition continues (Score:1)
Are you sure you didn't work for Microsoft?
No, you're the one on drugs (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 [google.com] is used in 1,210 pages, whereas tetralingual [google.com] is used in only 14.
I assume your Game Boy reference alluded to Tetris®. In that case, the existence of Quadra [sourceforge.net] negates any "by default, go with the name of the block game" rule. In other words, you need to lay off the drugs [pineight.com] ;-)
Re:Didn't Game Boy teach you anything? (Score:1)
"Someone set us up the bomb!" [toaplan.com]
Re:i know it's silly... (Score:2, Funny)
Of your list only C++ is a language. However one could right an Apache module in C++ that accesses a MySQL database... err wait actually that been done!
Re:i know it's silly... (Score:3, Funny)
Gees, maybe I need to stop reading
Re:If your brain is fucked, code in 4 languages? (Score:1)