Friday, August 14

How to Shoot Yourself in the Foot

The ideosynchracities of various programming languages, exposed through a crude metaphor. This joke has been around for a while, but I'm surprised to hear of some people who work with computers who haven't heard some of them yet..

So - for the benefit of those folk and others, here are a selection of some of my favorites.

C
You shoot yourself in the foot.

C++
You accidently create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying "That's me, over there."

ASP.NET
Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.

Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.

JavaScript
You've perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.

Forth
Foot yourself in the shoot.

APL
You shoot yourself in the foot; then spend all day figuring out how to do it in fewer characters.

PHP
You shoot yourself in the foot using bits of other guns you found on the web.

Brainfuck
+++[>-->+>-<<<]>.----->+.>[>----<].+++<--->[-].<--.
That took so long to get right, you must have shot yourself in the foot at least once by now.

Ruby
Your foot is ready to be shot, but you just can't find anywhere to shoot it.

Assembly
You crash the OS and overwrite the root disk. The system administrator arrives and shoots you in the foot. After a moment of contemplation, the administrator shoots himself in the foot and then hops around the room rabidly shooting at everyone in sight.

MUMPS
You shoot 583149 AK-47 teflon-tipped, hollow-point, armour-piercing bullets into even-numbered toes on odd-numbered feet of everyone in the building -- with one line of code. Three weeks later you shoot yourself in the head rather than try to modify that line.

Java
You locate the Gun class, but discover that the Bullet class is abstract, so you extend it and write the missing part of the implementation. Then you implement the ShootAble interface for your foot, and recompile the Foot class. The interface lets the bullet call the doDamage method on the Foot, so the Foot can damage itself in the most effective way. Now you run the program, and call the doShoot method on the instance of the Gun class. First the Gun creates an instance of Bullet, which calls the doFire method on the Gun. The Gun calls the hit(Bullet) method on the Foot, and the instance of Bullet is passed to the Foot. But this causes an IllegalHitByBullet exception to be thrown, and you die.

csh
You can't remember the syntax for anything in this language, so you spend five hours reading manual pages, then your foot falls asleep. You shoot the computer.

Lisp
You shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds...

SQL
INSERT INTO Foot
SELECT Bullet
FROM Gun.Hand
WHERE Chamber = 'loaded'
AND Trigger = 'pulled'

Genetic Algorithms
You create 10,000 strings describing the best way to shoot yourself in the foot. By the time the program produces the optimal solution, humans have evolved wings.

CSP
You merely fail to shoot everything that isn't your foot.

Fortran
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception processing ability.

Modula/2
After realizing that you can't actually accomplish anything in the language, you shoot yourself in the head.

370 JCL
You send your foot down to MIS with a 4000 page document explaining how you want it to be shot. Three years later, your foot comes back deep fried.

Hypertalk
Put the first bullet of the gun into foot left of leg of you. Answer the result.

BASIC
Shoot self in foot with water pistol. On big systems, continue until entire lower body is waterlogged.

COBOL
USEing a COLT45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER on HANDGUN.TRIGGER, and SQUEEZE. THEN return HANDGUN to HOLSTER. Check whether shoelace needs to be retied.

~~~~~~~~~

Okay, it seems it works for OS too:

Unix
You shoot yourself in the foot.

DOS
Cannot locate foot. Bad command or sight line.

AMIGA-DOS
It's a nice gun, but nobody's made bullets for it for over a decade.

Windows 3.1
You have a gun selecter, bullet pop-up help, and shooting sound effects - but you're unable to open shoot.dll...

Windows 95
Your gun is not compatible with these bullets and you must install an upgrade before you can continue. Then you will be informed that you don't have enough memory.

Windows Vista
Warning: Shooting yourself in the foot could potentially damage your foot. Are you sure you want to do this?

Windows 7
This gun does not come with bullets. Our marketing campaign will however recommend that you download bullets directly from us, maintaining our monopoly on both guns and bullets.

~~~~~~~~~

Some of these I wrote myself, some have been around longer than I have! Enjoy!

Thursday, May 14

Back to the Future

One point twenty one gigaWatts!

Time travel. Okay, so here's the deal. There's really nothing in the laws of physics which explicity prevent it under any circumstance. In fact, there's an abundance of loopholes and nifty tricks you can theoretically perform using current theories and exotic measures.

First, the future.

This is easy. Einstein's Theory of Special Relativity tells us (and this is totally 100% true) that the faster things move, the heavier they get, the thinner they get, and they experience less time than someone standing still. This effect is only really noticable when you get near to light speed.

So, you could zoom around in a spaceship at say 90% of the speed of light, return to Earth one year later - but you'd find it was actually two years later on Earth! The faster you go, the further you travel forward in time relative to everyone else.

Of course, going that fast takes a huge amount of energy, and the faster you go, the harder it gets to go faster. You can't reach light speed. So it'd generally be better to not have to go so fast in order to travel forwards. Thanks to Einstein's Theory of General Relativity - we don't have to. Instead, we bend space-time around ourselves to get a similar effect.

This is what's known as a gravity well. All matter bends space-time around it, and the more of it you get in one place (density), the steeper the sides of the well. If you could compact, say, a large planet like Jupiter down to... about the size of the Atomium in Brussels, then get inside - you'd get a very similar effect.


A lot of time travel tricks revolve around bending this space-time membrane in such a way that our normal everyday view of the world becomes warped, and things that seem completely impossible are in fact the only mathematically valid solution. We've demonstrated the future, is easy enough, but what about the past?

Coming Soon: Back To The Future II - wormholes, cosmic strings and other cheap tricks

CovertHolistic

Sunday, May 10

The Most Beautiful Equations

Sometimes mathematics is beautiful. It's a hard thing to observe; you need to peer through various mystifying levels of symmetries and distractions, until you finally arrive at that most elusive moment where you suddenly realise it's all really simple.

Many of the greatest equations, theories and postulates have relied on the power of their beauty. Einstein's E=mc2 has entered the public consciousness like no other, while many others intrigued and delighted the scientific community without much publicity.

Gauss
Gauss's integral for example, reduces this technically baffling integral to a silly and simple number - albeit one which goes on forever.. 1.772453850905516027298167483314...

Comprehending the lateral method used to solve this problem was a major moment in my scientific education. The solution appears to be infinitely unsolvable, if you think of 'x' being a straight line, which as far as any really grasped, was mostly what integration seemed to be about.

However, if you instead think of this problem in two equal dimensions, you can bend the co-ordinates into a circle. Suddenly, as the circle closes, the difficult bit drops off and you can solve the bugger easily to get 1.77...

This identity is used heavily in quantum mechanics, in fact - the whole field is underpinned by the kind of logic used in this solution.

Euler

Euler also used circles to describe other strange and useful numbers. Imagine a second hand travelling round the clock face. Imagine a straight line drawn from 9 to 3. The question is, how far away from that line is the tip of the second hand, as it travels round? If you plot a graph of that distance against time, you'll get a sine wave:



If you instead imagine a straight line between 12 and 6, and plot that, you'll get the same thing, except the start point will be a quarter of a circle further round. These two waves, one '3 hours' out of phase with the other, are called sin and cos.

We would usually use an angle called a radian instead of the clock metaphor. A clock has 12 hours, a circle has radians - twice the number π. So the two waves are π/2 ( 2π / 4 ) out of phase, and the two waves are sinθ and cosθ where θ revolves all the way around from 0 to 2π, like the hand making a full revolution.

Euler showed us that you can treat sin and cos as really the same things, if you use something called an imaginary number.

Okay, I'm thinking of a number. What is it? "Well.. " you say, "it could be anywhere between zero and infinity!" What about negative numbers? "Well, minus infinity to infinity then!".

And you'd have me there. But suppose instead I was thinking of the square of a number, there'd be no point guessing a negative number because any number, positive or negative, gives you a positive number when you square it. In fact, if someone claims they've thought of one, well, it can't be real can it? No real numbers do that! Must be some kind of.. imaginary number, hah!

In mathematics, existing and being real thankfully don't have to mean the same thing, so we can imagine numbers which exist but aren't real. They'll actually really useful, and in fact have a lot to do with circles, and waves, and lots of really geeky physics stuff.


Don't worry if that's a bit confusing, The point is, when you combine in the radian idea, the sin and cos, the imaginary number idea, and the exponential (I won't go into that here - check the link at betterexplained.com) you arrive at the most startlingly simple statement:

This, I believe, is the most beautiful equation. The soaring exponential, the elusive imaginary, the reliable circle, the triumphant '1', then equality to nothing. It's the poetry of the universe, and it's just the first line.