Div, IFrame, Form: the CSS version of Scissor, Paper, Stone

An interesting browser (mostly, it has to be said, Internet Explorer) rendering issue has produced an slightly odd workaround. The problem arises from the rendering of form elements, specifically dropdowns, by the browser. These are registered as windows components and hence are rendered somewhat outside of the other HTML elements. (This is not true in Firefox and other Mozilla based browsers which have their own rendering. It is painfully true of the old Netscape 4 where all form elements show through, but there’s no fix for that at all.) The same rendering issue is also true of frames, iframes and embedded objects (albeit Flash can now be specified with a transparent background).

This gives the situation where a layer (in a div tag) over the top of a dropdown box leaves half the select box visible through the layer. E.g.

Peekaboo!
I’d like to be on top

The code for this follows:

Peekaboo!
I'd like to be on top

The solution I’ve found is that IFrames can be rendered on top of select tags. Not much use in itself, but ever since Internet Explorer 5.5 it’s been possible to give IFrames a Z-Index and render layers on top of them. So in the rendering scheme of things:

  • select beats div
  • iframe beats select
  • div beats select

Hence the ‘Scissors, paper, stone’ reference of the title. The order does seem somewhat circular

To solve the IE rendering problem we can insert an iframe between the div and the select with the same dimensions as the div tag over the top, as follows:

Peekaboo!
I’d like to be on top

With the following HTML code

Peekaboo!
I'd like to be on top

Gambling in the UK, have they never played Sim City?

With the prospect of legalised casino’s in the UK, the parallels between the
‘real’ world and Sim City seem ever closer. Personally, I don’t know what
the moral arguments before and against are, but if the government had ever
played Sim City but the legalisation of
gambling in that game always resulted in higher crime and, longer term, ran
an area downhill so that no other businesses wanted to move in.

The BBC’s take
on the merits of legalising gambling can be read here

Class type hinting in PHP 5

PHP 5’s OO structure is way ahead of PHP 4 and has so many ‘proper’ object oriented concepts built into it that writing well-structured code is much easier than ever. The problem that PHP faces (and may always face) is that being a loosely-typed language (click here for an explanation of the differences between PHP and other languages) there’s no real way to enforce the type of objects that are passed between methods, or to overload methods in the sense of the word used by Java, C# and other OO languages.

One thing that PHP5 does allow, however, is what they call ‘class type hinting’. This allows you to specify the type of object which is passed into a method and, if a variable is passed in incorrectly, then a runtime error is generated. E.g.

class Foo
{
  public function __construct(Bar $bar)
  {
  }
}

$foo = new Foo($bar);

This will throw an error if $bar doesn’t contain an object of class Bar.

This is a step forward in that at least you get a warning about your code breaking closer to where it actually happened than, perhaps, five methods down the line when you actually try and do something with the incorrect object, but there are a couple of parts of the implementation that I still don’t really like.

The first problem is that the error message only gives the line number of the method that’s called, not the callee so there’s still some back-tracking to find the source of the error. Still, beggars can’t be choosers…

The other is that some of the built-in types don’t seem to be recognised. Therefore you can specify your own classes by name but using ‘String $myString’ or ‘Array $myArray’ doesn’t wash with the interpreter. This means you have to leave those untyped, which kind of defeats the purpose in some cases.

The other issues are really to do with a wish-list. What would be really good would be:

  • Overloading: to be able to define more than one method of the same name.
  • Specifying the return type from a method. E.g. Foo $foo = $new Foo(); Bar $bar = $foo->makeBar();

I don’t know whether that’s ever going to be possible given loose typing but I don’t think PHP 5 will be regarded as a true rock-solid OO language without them.

Spam: I just don’t get it.

Actually, I get a lot of it. Spam comes flooding through old e-mail in a
constant stream. The thing I don’t get is: what is the spammer getting out
of it? I mean, most of the e-mails at the moment are for one of:

  • Rolex’s: as if they’re genuine. Yeah, right.
  • Various pharmaceuticals: I don’t even know what these are. What the hell
    is a ‘soft tab’? Why is it better than not being a soft tab? (I really don’t
    want to know, by the way.)
  • Mortgage approvals: hang on, what a great idea, I’ll hand over the deeds
    to my house to someone in another country from a company I’ve never heard
    of! What a waste of time.
  • Cheeaap Softwarrreees!: OEM Photoshop! What a bargain! If such a thing existed, I might just be tempted. But then again, probably not.

Okay, I’ve seen an
article on the economics of spam on The Register
that reckons only 50
in every million people need to respond to make money, but 50 seems a high
number for these obviously useless e-mails. I guess someone must be making
money out of it, but who?

The best theory I can come up with is that the people who are doing the
spamming are selling their services to people who are probably even more
gullible than the intended victims of spam: those people who think they can
send a few million e-mails and make their internet fortune. The market for
get-rich-quick schemes is always busy…

Incidentally, as an excellent way to catch spam I’ve been using Robin Keir’s K9 Spam Filter, which is
free and extremely good.

JavaScript Haiku

There are a few sites on the web which will generate haiku’s using a set of code rules. I think I can lay claim to have written what could be the world’s first (and only) haiku actually in JavaScript. I’m quite interested in the idea of code being poetry, but just generally not interested enough to do anything about it…

It even has a title which relates to its content, which is:

Fear of tomorrow

now = new Date();
day = now.getDate();
alert(day+1);

Brussels freelancers beer night

Some of us from www.freelancers.net have just come back from a great couple of nights in Brussels. I’ve never been to Belgium before but it was a great laugh. We stayed in the ‘Hotel Catalonia’, which was a pretty good place, somewhere in the Art Nouveau quarter. It was pretty short on art nouveau, however…

The full attendees were:

  • Karl Bunyan (me)
  • Deborah Causton
  • Dave Edwards
  • Susan Engel
  • Lindsey Hill
  • Luke Perman
  • Paul J White

I’m not going to put the full details here (even if I could remember them…) but a few photos are below:

Luke pointing at a statue

Black and white shot of me and Luke

Lindsey, Susan and Luke

Dave and Susan

Paul, not too drunk yet

Deborah, on a rare occassion when she isn’t hiding

Me with a glass of Kwak. I really did turn into Mr Hyde later that night.

Susan, Luke and myself on our way to the Eurostar.

Me hiding. Sweatshirt sleeve/mask of zorro.

Susan, Dave, Paul and thumbs

Dave goes for his guns/beer

Hot chocolate self-assembly kit before

Hot chocolate self-assembly kit after

Group photo: Susan, Luke, Lindsey, Dave, Me (and Paul behind the camera)

Susan and Linsey

It rained a bit while we were there…

We know exactly where we are, honest.

Me, Luke and beer. Such a rare sight to see together.

A student beer-and-lorry-fest. No idea what this was all about.

Princess Susan

Mealtime

Another shot of someone drinking (spot a theme?)

Dave and Deborah, before Deborah had a chance to hide

An overturned car that Paul spotted coming out of an underpass

The window of our hotel. Fascinating.

Lindsey, Luke, Susan and Paul (from left to right)

X-Entertainment – Spider-Man Reviews Crayons! Part 1 of 3

“Spider-man Reviews Crayons” is hilarious. Definitely worth a read of the whole thing…
X-Entertainment – Spider-Man Reviews Crayons! Part 1 of 3.

Basically, Spiderman has signed up to a deal to review a full set of Crayola crayons. The pictures are absolutely superb… I don’t know how they managed to get a plastic Spiderman figure to have an expression on his face, but he does.