On 17 Mar 2008, at 21:58, Gunnar Hjalmarsson wrote:

In this case, if I understand it correctly, the default version of the page, with a form, would appear. Why would that be a problem for anybody but the stupid user? ;-)

Fundamentally, don't make it possible for your users to do anything to surprise you.

It would have been a benign surprise this time, once these bad habits become entrenched it will only be a matter of time before you get a nasty surprise.

Case in point:

I once wrote some indexing code, things being what they were I had to make fairly efficient use of disk space. I decided on a simple bit- packing scheme, so each byte could flag the existence of a word in up to 8 objects. With sparse files, this was quite efficient indeed.

Somewhere in the code I had a check like this:

if (! $index_byte ) {
  [ code to process the next byte ]
}
else {
  [ process this byte ]
}

Seems pretty bulletproof doesn't it? If the index byte is empty then we skip on to the next byte, as we don't have any entries at all for those 8 objects.

Testing showed a problem.... occasionally index entries were missing. A lot of digging found the culprit.... if you have a scalar byte holding 8 bits worth of data, it's not just when it holds 0x00 that that test is true - it's also when it holds 0x30 - ascii '0'.

ALWAYS make your tests as specific as possible, and care about the exceptions.

        - Justin

--
Justin Hawkins
[EMAIL PROTECTED]
http://hawkins.id.au/~justin/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to