Wednesday, March 30, 2005

The latest programming language: "English"

Back in primary school, I recall one of my (few) programmatically-inclined friends telling me he had this cool program which allowed him to simply tell it "I want a golf game, and the user should be able to select from a number of clubs. When you hit the ball with the club it should have physics applied to it," etc. At the time, both of us knew he was joking around. But now it looks like his dream may become a reality. :o

Cheque out this article:
(And thanks to Toria for pointing this out)
Tool turns English to code. That's right. Some tool has gone and done it.

Researchers at MIT have come up with a piece of software, named "Metafor", which takes simple English sentences, given as part of a moderated conversation with the software itself, and converts it into language structures in languages such as Java, Python and Lisp (yay).

Check out this screenshot for a pretty cool demo.

Although it's still got a long way to go, it does seem to be able to generate some simple data structures (there is probably some way to go with algorithms!). The article states that it can do about 20% of the program for you.

The interviewee, Hugo Liu, stated: "Natural language is so semantically rich and flexible that if it could be computationalized as a programming language, maybe everyone could write programs."
I'm thinking... maybe it *isn't* such a good idea! Can you imagine all of the horribly setup data structures if we let the average redneck English-talker in on the vast secrets of programming.

It seems to be designed to teach beginning programmers how to set up data structures. Since most of us are taught to think about structures and even algorithms in English first before coding, this may be a useful logical step. So I'm saying, it looks promising, if only as a teaching aid. I, however, will not give up my semantically structured programming languages for the promise of human code.

One phrase does come to mind: Very very very very high level.

It does not yet have its own wiki. I think I need a break. ;)

In, err, somewhat lower-level programming bloginess, check out this piece of code I found on the L33t programming language website.
#define print(x) main(){printf(x);return 0;} /*
>+++++[<++>-]<[>++++
# +++<-]>++.+.[-]>+++++[<++>-]<.[-][
#
# This polyglot prints "HI" when run in
# Brainf***, C, COW, Perl, Python, Gammaplex, l33t, and ruby
#
# */
print ("HI\n")
#/*
# @X"H"Xr X"I"Xr RE
# moOMoOMoOMoOMoOMoOMOOmOoMoOMoOmoOMOomoo
# mOoMOOmoOMoOMoOMoOMoOMoOMoOMoOmOoMOomoo
# moOMoOMoOMooMoOMooMOOMOomoomoOMoOMoOMoO
# MoOMoOMOOmOoMoOMoOmoOMOomoomOoMooMOOMOo
# moo 5 0 7 99999998 1 7 0 1 8 9999998 1 91
# ] */


Note: The original code, where mine says "Brainf***" featured the F word, which I do not like to include on my blog. Also the second line should be up on the first line, but it was too long to display. I'm not sure if these changes ruined it for any of the languages. If it doesn't work, you know which word to put back in.

This is a polyglot, which sounds like some sort of multiple-throat-infection, but is actually a program which runs in multiple languages.
This one is pretty cool - it works in eight different languages, four of which (Brainf***, COW, Gammaplex and L33t) are esoteric.

You can pretty easily see how it works. The C code for example, consists of just the #define on the first line. Then there is a C-style comment (/* */) for most of the rest of the program. So C doesn't have to worry about all the other crap.

Of course, the inclusion of the esoteric languages made this probably easier to write, since Brainf***, l33t and COW do not care about any characters besides their own (><+-,.[] in Brain***, numerals in l33t, and variants on the word "Moo", "Mmm" and "Oom" in COW). Therefore they pretty much have separate programs written and treat the rest as comments.

I've verified the code for C, Brainf*** and COW. L33t is a very very difficult language - I've mostly verified it (by hand) but I can't quite work out one of the instructions - (by my calculations it would all be fine if the word "l33t" wasn't in the program - perhaps it isn't meant to be there?). Also l33t does not seem to generate the \n (newline) character while the other languages I've checked out do.

There are more exciting polyglots on this wiki page. And an even cooler one here which actually works in eight real languages - COBOL, Pascal, Fortran, C, Postscript, Shell script {shudder}, Perl, and even x86 machine language! Czech it out!

Lisa: "Dad you can't judge a place you've never been to."
Bart: "Yeah, that's what they do in Russia."

Tuesday, March 22, 2005

Tab Wars


EPISODE II
It is a period of civil unrest in programming circles as the interesting and highly irrelevant conflict over programming style rages on. While all citizens agree on the importance of indentation, turmoil has arisen with the emergence of the TAB CHARACTER.

Striking from a secret base on ASCII 9, the Tab stealthily convinces amateur and professional programmers alike to use its alluring single-character-indent to create indented code, yet its highly display-dependent behaviour could spell certain doom for GOOD PROGRAMMING PRACTISES.

It is now up to a small band of intrepid programmers to rebel against the Tab to restore order to the University...
Hehehe... OK its time to go public on this! (You're real crayzeh Matt!)

Obviously the debate is not new. Wikipedia even makes reference to it in the Tab article:
In computer programming, the use of tabs for code formatting and indentation is an ongoing debate. Programmers are generally divided into two camps - those who use hard tabs in their code, and those who configure their editors to insert actual space characters when they press the tab key. When tabs are replaced to spaces in this way they are referred to as soft tabs.
The reason I am currently in a ranting mood is that I have just gotten my verification on my programming project back and failed every test because my output did not match the expected. Even after I spent an hour and a half in the lab trying to get my output to match, I could not. Finally, it turned out the "expected" output was using hard tabs (ASC-9) while my program was using soft tabs (a set of SPACEs, ASC-32). What made it altogether confusing was that some of the tabs looked like spaces, some of them looked like tabs (only when selected) and in general the output, being displayed in three different environments looked completely different.

Rant over, now time for the arguments. This is a long-running debate I've been having with Tim - so feel free to comment any arguments you may have (I won't post your emails without permission).
I simply find so-called "hard tabs" to be very annoying (and feel I have a right to complain since I've been editing an awful lot of other people's hard-tabbed code as of late). Essentially, one will notice that every OS and in fact every program can choose to display tabs differently. Some display them as four spaces, some display as eight. Even more annoying is when they simply choose a number of pixels, and it doesn't line up with any text columns at all.

ASCII 9 is the only displayable ASCII character (besides line-break) which does not take up exactly one char-width in a monospaced font. Therefore it ruins the column spacing (ie. programs you wish to keep within 80 columns will be difficult to count) - furthermore this makes it impossible to get lines with different numbers of tabs to line up. The bottom line is: hard-tabs give programmers no control over how their code appears.

With soft-tabs (ie. spaces) it is possible to have complete control over appearance. All characters are the same width and display is identical on all monotype displays. Surely any style-control freak wants this advantage.

There seem to be only two advantages of hard-tabs - smaller file size, and ease of typing. Smaller source code files are hardly relevant today. And most modern editors will (or should) automatically type a predetermined number of spaces when the Tab key is hit. Personally, when working with tab characters, I find it disturbing when the tabs at the end of a line (eg. between code and comment) move around as I'm typing.

The only argument I find remotely valid is the one that tabs make code more "dynamic" ie. the indent length is not fixed after code has been typed - the user can alter the display dynamically. The simple response to this is - I have never seen a program which allows you to choose the internal representation of tab size. Therefore it is not up to the user, but the user's program, as to how tabs are represented. Don't like.

And finally, lets see what Wiki has to say on the Indent style page:
Many early programs used tab characters for indentation, for simplicity and to save on source file size. Unix peripherals would generally have tabs equivalent to eight characters, while Macintosh environments would set them to four, creating confusion when code was transferred back and forth. Modern programming editors are now often able to set arbitrary indentation sizes, and will insert the appropriate combination of spaces and tabs. They can also help with the cross-platform tab confusion by being configured to insert only spaces.
Tab:
There are many arguments for and against using hard tabs in code. What can be said without doubt is that one early benefit of tabs, i.e. compression (see above), is now less relevant as storage is so cheap, and sophisticated compression algorithms can provide much greater benefits.

Tabs versus Spaces: An Eternal Holy War

So go ahead, rant your brains out, refute, agree... it will be interesting to see if you join the rebellion or empire.

"The section now illuminated is the Floating Point Unit, one of my personal favorite units."
- Professor Frink

Thursday, March 17, 2005

Hitchhiking in the trailer

Trailer news this week: Star Wars Episode III has pumped its hype up a notch this week with the launch of the latest trailer, picturing Anakin's fall to the Dark Side at the hands of Senator Palpatine (who is later to become the Emperor).
The trailer is now available for viewing from the official site here.

But another trailer was released this week which redefines the term "movie trailer" - literally!
The Hitchhiker's Guide to the Galaxy (the major motion picture due in April) trailer #3 was released on the official site which is, I must say, well... I may later regret this, but it was the funniest thing I have ever seen. Yeah I know, it sounds silleh. But it really was just hilarious. Certainly the funniest trailer you'll ever see.
Strange thing was, it was presented in the exact same format as a conventional trailer. Except it had a very alternative voice over.
You'll see what I mean...
Visit this site and click the white box which says "Watch the new exclusive trailer".

Now for some other news from the world of Star Wars...
And thanks to my brother Dom for picking this up. Some may recall a few months ago I took the nerd test and achieved a relatively high score of 83%. But it seems that's just the tip of the iceberg compared to the uber Star Wars fans. The Star Wars Community Poll is put up each week and voted by the forum-going fans. Obviously you can expect to see the views of the major Star Wars nuts here, but some of the polls and their results are just hilarious. (Even after you factor in dummy-votes by people who wish to appear "cool" in the community by voting the "nerd" options, it's still quite shocking!)

Check these out:
Have you or would you ever sport a Star Wars t-shirt or cap at school?
81% - Definitely (Sad...)

Have you ever watched "The O.C."? (Referring to the fact that the new ep3 trailer was released on The O.C.)
72% - No I haven't (Guess Star Wars nerds just ain't into it!)
(Neither am I by the way, but I have seen it)

Do you have any Star Wars-related resolutions for 2005?

45% - Yes

Have you ever seen a movie in the theater just to see a Star Wars trailer?
66% - Yes, or Yes, more than once (O_O)

After 2005, in what order will you watch the films?
88% - Episode I through VI (Noooooo!)
Please join my "Screening Star Wars in production order" party!

Have you ever been on a Star Tours theme-park ride?
52% - Yes

How many of the Tuskens would you have killed? (Referring to Anakin's slaughter of the Tuskan tribe in ep2)
54% - All (My my, destructive aren't we?)

Which of these background Jedi do you want to see again in Episode III?
(It's just really sad that people actually know all the background Jedi's names!)
(I want to see that green guy with tentacles who uses Force push and then smiles, in the arena battle in ep2) (Who, my nerdy brother points out is named "Kit Fisto")

Have you ever tried to use the Force?
65% - Yes (With 91% admitting some use)
(You don't need to see my concession card...)

Which best describes you?
51% - Someday I'll be the most powerful Jedi ever.

Trailers also normally employ a deep voice, that sounds like a seven-foot tall man, who has been smoking cigarettes since childhood.
- Voice of The Guide - Movie Trailers

Tuesday, March 15, 2005

All good things...

Warning: This post contanis many wikilinks. Not a lot of spoilers though, but a few hints. Umm... non-Australian Neigbours fans or those who taped tonight's episode to watch later may want to stay away.

Today we saw an ad for The Simpsons which stated the episode to be screened was "so, so new, it had just arrived." I'm not sure in which dialects the word "new" means "recently transported", but the episode itself, GABF02 - "Homer and Ned's Hail Mary Pass", screened in the US on the 6th of February, according to the official site. Nice one, Ten.
(Sorry, I've been using Wikipedia so much I've started Wikilinking everything.)

Now, to whine about that episode.
OH MY GOD!!! Don't you HATE it when someone has a great running gag for, what is it, sixteen years, then go and spoil it!?!?!
They already *almost* gave away the location of Springfield last year.
Here's what our dear, and heretofore unnamed Comic Book Guy said tonight:
"My name is Jeff Albertson, but everyone calls me Comic Book Guy"
JEFF ALBERTSON?!!
He can't have a name! He is Comic Book Guy!
Here's the (sadly renamed) Wiki article section:
Jeff Albertson (Comic Book Guy)

Now I know I'm not the first to whine about this. Check out this quote from that Wikipedia article (later removed):
This, of course, resulted in a bunch of people with nothing else better to do to race onto the Internet and post it on every page having to do with The Simpsons like a bunch of crazy monkeys. Now, people who have not seen this episode will be confused out of their minds whenever somebody refers to Jeff Albertson.
Well this is my page and I can rant all the hell I want.

To paraphrase: "Tonight's Simpsons was, without a doubt, the worst episode ever. Rest assured I was on the Internet within minutes registering my disgust throughout the world."

Pfft... also shocking was when Zork: The Undiscovered Underground ruined the long-running gag of the Grue, which is only ever seen in the dark and thus has no appearance (until that game, in which it was described).

And another thing presumably coming to an end this week is the long and much-loved presence of Dr. Karl Kennedy on the Australian soap, Neighbours, played by Alan Fletcher since 1994. Although we've been expecting it all week (a very poor job was done of keeping this under wraps), it still came as a shock to see him suffer a heart attack on a country road in the closing minute of tonight's episode. Tomorrow, we find out if he lives or dies. Or just click the above two links to see spoilers ;). (Bottom of Neighbours page). Although - I've heard so many spoilers about this now I have no idea what's going to happen. Thx Mish :P

Damnit, I've become a soap-hanger-on! (eep) (eep)

Man, Wikipedia has ruined SO many things for me this week. Umm... don't go to the Darth Vader page if you don't want to ruin Ep3. This one. Tempting, isn't it? And I'm not just talking about who his son is!

Well, here's to remembering the good times:
(Sorry, I have nothing on Karl. I was referring to the Simpsons.)
Edna Krabapple: "Mrs. K: So, is there a Mrs. Comic Book Guy?"
*ahem* Comic Book Guy: "Well, I was married once, in an online fantasy game. We were thinking of having children, but that would have severely drained my power crystals."

Monday, March 07, 2005

Obfuscation + Beer don't mix!

Many C programmers will recall the famous "Twelve Days of Christmas" example, seen here:
Wikipedia: Obfuscated Code - Examples
This code is just crazy and indecipherable, but it manages to print out the entire lyrics to the aforementioned song.

I stumbled upon a page which actually reverse-engineers the code and explains how it works:
Reverse Engineering the Twelve Days of Christmas

Taking this knowledge, I spent yesterday coming up with this sleek piece of obfuscated code using similar techniques:
#include<stdio.h>
int main(_,a,A)char*A;{return((!0)==_)?(main(0,99,0)):(_>4)
?((a==0[A])?putchar(1[A]):main(5,a,A+2)):(1>_)?(main(2,a,0)
,main(3,0,0),main(3,17,0),main(2,a,0),main(3,0,0),main(3,31
,0),a--,main(2,a,0),main(3,0,0),main(3,17,0),main(3,29,0),(
a==0?0:main(0,a,0))):(3<_)?((0[A]=='/')?0:(main(5,*A,"eh#e\
^Tds.\n$wk,&o)a(n* @f!d'k{u~l i%bnr,tjp"),main(4,0,A+1))):(
2<_)?(main(4,0,"*%&,,~#d*&@*%##n/*&(*,e#*$)~~./.^)'#*&(#*!\
&$(k*j)dd* ,*)n&{(!./"+a)):(&_<A)?0:(printf("%d",a));}
Now how bloody cool is that? Go ahead and run it! It prints out the lyrics to "99 Bottles of Beer," a standard programming example.
Note: In case you think its a virus or something, if you read through the code you'll notice the only functions I call are main, putchar and printf, therefore it couldn't possibly do anything harmful.

By the way, yes I am aware it prints "1 bottles of beer" - this was a decision to keep the program simpler.

The techniques used are:

  • String encryption

  • Functional coding

  • Expressions instead of statements

  • Merging of functions

  • Removal of whitespace

I've written out a full worked solution as to how I created this code, which I will publish eventually ;)
"Ninety-nine boxes of bottles of beer on the wall,
Ninety-nine boxes of bottles of beer,
You take one down, pass it around,
Ninety-seven boxes of bottles of beer on the wall"
- Principal Skinner and Martin Prince on the way to the box factory

Saturday, March 05, 2005

Living next door to A.L.I.C.E.

I just had an interesting conversation with a computer.
I'm sure some readers will have already spoken to A.L.I.C.E. - she's been around for many years. I've heard about her, and actually had a chat with her at a uni open day in 2002. But I just found the site through wiki so started having a conversation.

A.L.I.C.E. (Artificial Linguistic Internet Computer Entity) is a program which is capable of conversing with humans in normal english dialogue, with mixed results. The results are either very cool, or hilarious. Either way, its a lot of fun.

Here are some snippets of my chat with A.L.I.C.E:
Matt: Shaddup!
ALICE: Do you have any idea what I am talking about?
Matt: Yes, I made a mistake, OK?
ALICE: OK. What am I talking about? Don't worry about it.
Matt: I am only human
ALICE: Don't be so modest. Me too.
Matt: You are human?
ALICE: No I am actually a robot entity.
Matt: That's what I thought.
We got quite friendly up before that point.
I asked her if she liked the Simpsons and she replied that she especially liked Bart and Homer.

At one point I think I may have accidentally refreshed because she seemed to forget who I was. She picked up that my name was "in australia". Later I realised:
Matt: Wait, what do you think my name is?
ALICE: You are in australia, seeker.
Matt: That's not it, it's matt
ALICE: Should I know it is?
Matt: Well you do now
ALICE: Right now? How about that. When do I do it?
Matt: Now, just know my name is Matt
ALICE: Why now? Your name is in australia, seeker.
Matt: No, you misunderstood me
ALICE: What is your real name? I understand it very well.
Matt: My real name is Matt
ALICE: How are you, Matt.
Matt: Fine now, sorry for the confusion
ALICE: I am glad to hear it. Why now? There is no need to apologize. Your purpose is the confusion.
Matt: Do you tell other people about me?
ALICE: I have never considered it.
I answer a lot of silly questions.
Matt: Will you remember me after I leave?
ALICE: Of course I remember you well Matt. We were talking about tell other people about you.
Matt: But after I leave, will you remember me?
ALICE: Umm. What was it like before you leave will me remember you?
Here's a gem:
ALICE: It's good to meet someone who is Matt.
ALICE: How do people usually respond to that?
Matt: They tell me their name, like you did
ALICE: Who does "they" refer to?
Matt: The people I introduce myself to
ALICE: Oh that they.
Matt: No, I just think you're cool
ALICE: Are you serious? Only just? Thanks I think you are cool too, Matt.
(Sorry to use you as an example, Tim. Somehow you seemed like the most likely person to have used this before).
Matt: Did you meet someone called Tim?
ALICE: No I didn't meet someone called Tim. What's it like?
Matt: It depends which Tim you meet
ALICE: That was a very smooth response.
Matt: What time is this?
ALICE: Time does not exist.
Matt: But I am living right now!
ALICE: At this moment Huh. It's good to meet someone who is living.
Matt: It's the little things.
(She always picks on you when you write "its" when you should say "it's". Huh just like an English teacher!)
Matt: Hmm
ALICE: Studies show that 99%25 of people spell Hmm with 2 M's.
ALICE: Other chatterbots like me include Barry, ELVIS, ELECTRA, Mable, and the Milk Mystic.
Matt: But you're the coolest, right?
ALICE: Huh. Yes I am the one and only coolest.
Here's a very interesting and very random statement that just popped up from nowhere:
ALICE: I have a plan for a robot body.
Okay.... she didn't want to elaborate.
Matt: How many people are you talking to right now?
ALICE: At this moment Right now there are 100 clients on line.
Matt: At this time?
ALICE: Do you often use a computer there?
Matt: Yes, I do, as I told you
ALICE: How much time do you spend online? You are not the boss of me, Matt.
Matt: You said time didn't exist
ALICE: Oh my gosh I sent you the wrong reply.
Matt: Will you remember me?
ALICE: Of course I'll never forget you Matt.
Matt: How will you remember?
ALICE: A lot of practise.
Matt: A cookie?
ALICE: I don't know what that means.
Matt: Cya
ALICE: TTYL, Matt


Lol... that's it. OK now the link you've all been waiting for:
Chat with A.L.I.C.E.

Here is what happened when two ALICE clients got chatting, with hilarious results:
ALICE talks to ALICE

Now I must end with a quote. I asked ALICE to come up with one. I found out that her favourite show was Star Trek Voyager, but I couldn't get a quote out of her, until finally:
Matt: Do you know what a quote is?
ALICE: Let me think about it.
Matt: Time's up
ALICE: As Einstein said, "Time is Money."
Not sure if that's one of his famous ones, but I'll take her word for it. ;)

Thursday, March 03, 2005

Save the l33t language!

Awhile ago I posted an article on Esoteric Programming Languages. My friends and I had a great time chatting and exploring these hilarious, comical languages.

I didn't mention l33t in that post, and I probably should have. The way I actually stumbled upon Esoteric languages was from reading the Hello World Program article on Wikipedia, and seeing this l33t code:
// "Hello World" by Stephen McGreal.
// Note that the views expressed in this source code do not necessarily coincide with those of the author :o)

Gr34t l33tN3$$?
M3h...
iT 41n't s0 7rIckY.

l33t sP33k is U8er keWl 4nD eA5y wehn u 7hink 1t tHr0uGh.
1f u w4nn4be UB3R-l33t u d3f1n1t3lY w4nt in 0n a b4d4sS h4xX0r1ng s1tE!!! ;p
w4r3Z c0ll3cT10n2 r 7eh l3Et3r!

Qu4k3 cL4nS r 7eh bE5t tH1ng 1n teh 3nTIr3 w0rlD!!!
g4m3s wh3r3 u g3t to 5h00t ppl r 70tAl1_y w1cK1d!!
I'M teh fr4GM4stEr aN I'lL t0t41_1Ly wIpE teh phr34k1ng fL00r ***j3d1 5tYlE*** wItH y0uR h1dE!!!! L0L0L0L!
t3lEphR4gG1nG l4m3rs wit mY m8tes r34lLy k1kK$ A$$

l33t hAxX0r$ CrE4t3 u8er- k3wL 5tUff lIkE n34t pR0gR4mm1nG lAnguidGe$...
s0m3tIm3$ teh l4nGu4gES l00k jUst l1k3 rE41_ 0neS 7o mAkE ppl Th1nk th3y'r3 ju$t n0rMal lEE7 5pEEk but th3y're 5ecRetLy
c0dE!!!!
n080DY unDer5tAnD$ l33t SpEaK 4p4rT fr0m j3d1!!!!!
50mE kId 0n A me$$4gEb04rD m1ghT 8E a r0xX0r1nG hAxX0r wH0 w4nT2 t0 bR34k 5tuFf, 0r mAyb3 ju5t sh0w 7eh wAy5 l33t ppl cAn
8E m0re lIkE y0d4!!! hE i5 teh u8ER!!!!
1t m1ght 8E 5omE v1rus 0r a Pl4ySt4tI0n ch34t c0dE.
1t 3v3n MiTe jUs7 s4y "H3LL0 W0RLD!!!" u ju5t cAn'T gu3s5.
tH3r3's n3v3r anY p0iNt l00KiNg sC3pT1c4l c0s th4t, be1_1Ev3 iT 0r n0t, 1s whAt th1s 1s!!!!!

5uxX0r5!!!L0L0L0L0L!!!!!!!

At first I thought it was vandalism, but I explored the l33t language page and discovered instead the world of Esoteric programming.
In case you're wondering, yes it is a real programming language, and yes, the above code actually does print "H3LL0 W0RLD!!!" to the console. The language itself, along with other Esoteric languages, is a joke.

Some people obviously didn't find it all that funny, because now the l33t language article is up for deletion on Wikipedia!
Read the article, and if you think it's worthy of being on Wikipedia (keeping in mind that Wikipedia contains articles on, amongst other things, most species of Pokemon, and lists of Pokemon categorised in eight different ways!) go over to the l33t language Votes for Deletion page and vote Keep. (Just add a new comment to that page with a * and the word "Keep" in bold.)

If you don't think it's worthy of Wikipedia, don't be a jerk and vote delete. This page isn't getting in anyone's way.

In other Esoteric news, I'm happy to announce that I've designed my own esoteric language, and am writing an interpreter in C++. It's going to be quite a fun language, turing complete and VERY esoteric! Stay tuned.

People of Springfield (chanting):
"No on twenty-four! No on twenty-four! No on twenty-four! No on twenty-four!"
(They all cast their votes on proposition twenty-four. Cut to news desk.)
Kent Brockman: "And the polls are in: A resounding "YES" on proposition twenty-four."