Failing with grace and artistry

1 Jun 2007

, ,


One of the problems I’ve always had with PHP error handling is catching the fatal errors. If a php script encounters a fatal error it stops, and the desired error handling code does not get executed.

So the user will (usually) be confronted with a blank screen and, worse still, since the error isn’t logged I don’t know about it and therefore can’t fix it.

It’s a rare and confident user who will report a blank page or other such glitch; people are so used to working with a certain level of pain when using a computer that they just assume it’s unavoidable or that it’s been caused by their own inadequacy in some way.

Anyway, (thank-you PHP London user group) I now have a solution using the register_shutdown_function()

<?
register_shutdown_function('cleanExit');

// ... go and do all sorts of exciting stuff ...

$running = false;

function cleanExit() {
	if ($GLOBALS['running'])) {
		// script is still running - it's an ERROR
		// tell Bronwen about the error
		// tell user it's not their fault
	}
}
>

Table names in MySQL

13 Apr 2007


To quote from the manual

In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Consequently, the case sensitivity of the underlying operating system determines the case sensitivity of database and table names. This means database and table names are case sensitive in most varieties of Unix

I always get bitten by this and am now making a blog entry in the hope that I’ll remember.

I have one client where their ecommerce system was setup using SquirrelCart. I came along later and built an admin module so they could manage the rest of the site. The squirrelcart has tablenames in mixed-case, but I always use lower-case for all table and field names.

Occasionally I’ll write some code to query squirrelcart tables. (E.g. squirrelcart lets people use discount codes but it doesn’t report on how often the discount codes are used, so that’s an add-on) My code always works when I test it on the development machine, but flips when I upload it. And it’s because I type the squirrelcart table names in lowercase.

New laptop stand


My standard machine is now a laptop, and at home I’m fine. I’ve bought a laptop shelf for my desk and the laptop sits at the correct height and it’s all very ergonomic and I am not having any back problems. (Two years I had a trapped nerve in my back, and it hurt. Physiotherapy and attention to posture and working environment helped, but I’m now very careful.)

The problem comes when I’m in someone else’s office or working away from my desk. The standard laptop working position leaves you hunched over the keyboard like a vulture crouched over road kill, and peering down at the screen. I like the screen at eye level. I need the screen at eye level.

So I need a laptop stand. Piles of books are at best a temporary measure.

Criteria:

  • The stand has to get the laptop screen up to the height of an LCP monitor. I’m not interested in anything which raises the laptop a miserly three inches off the table, or any product which describes itself as ‘laptop feet’
  • It has to be adjustable.
    I’m in charge and I want to be able to control position, and height.
  • My laptop is portable. My laptop stand must also be portable.
    And when I say portable, I mean it must fit in the rucksack with the laptop and all the cables, add-ons, and dinky gadgets. So I’m not interested in the stylish brushed aluminium design which will “enhance your working environment”

Last week I bought a folding laptop stand. It works. It does what I want. I’m a happy customer.

Hints for the home worker:
Over Christmas I spent some time on the sofa with the cat on my lap and the laptop balanced on the arm of the sofa. Bad idea. My neck hurt for the next two days. If you’re going to stroke a cat and browse the internet, put the cat on the desk with the laptop.

Amendment July 2007
Janet has recommended Bakkerel Huizen

Lorem Ipsum Garbage

22 Mar 2007


Sometimes you read something and just go “Yes!” to it. The following articulated perfectly my grudge against Lorem Ipsum filler text – basically no one wants to read this garbage so it ends up at 8px white text on a black background.

By not having the imagination to imagine what the content “might” be, a design consideration is lost. Meaning becomes obfuscated because “it’s just text”, understandability gets compromised because nobody realized that this text stuff was actually meant to be read. Opportunities get lost because the lorem ipsum garbage that you used instead of real content didn’t suggest opportunities. The text then gets made really small, because, it’s not meant to be used, we might as well create loads of that lovely white space.

From I hate Lorem Ipsum and Lorem Ipsum Users by Tom Smith

And I found Tom Smith’s blog entry via Getting Real by 37Signals; a collection of essays where I find myself saying “Yes!” a lot!

How to motivate yourself to update websites

1 Mar 2007


I’ve finally gotten round to updating my website, and adding a few of the projects I’ve been working on in the past year.

When I started this business a year ago I put up a thumbnail and a one-line summary for a few sample projects – which I picked primarily on the basis that they had interesting homepages and would make pretty thumbnails. And since then I’ve done very little. The blog gets updated intermittently, the website and list of projects not at all. Well, I’ve been busy, and I get people by referral or word of mouth rather than via the website, so updating content somehow never quite made it to the top of the To-Do list.

But today I’ve made myself a deadline. I’ve written a proposal which our potential client will receive tomorrow. In it there is a line saying “see website for details of previous projects”. So by tomorrow there must be details of some previous projects up on this website. That’s a deadline.
But I’m finding it tough going.

Each page must have a screenshot or two to make it look pretty, and because one picture is worth one thousand words and I really don’t want to write a thousand words, and if I did no one would read them.

Selecting, taking and editing the screenshots takes time. I’ve spent even more time setting up a nice little slide show so people could cycle through’ the multiple screenshots but decided that this didn’t work unless all the images were high-quality and precisely aligned. Nice for photos, slightly less impressive for pictures of blurry text.

The text must be clear and meaningful, and avoid the temptations of evil management speak (e.g. “holistic interactive enterprise internet communication solution”)

It has to summarise the project. Sometimes easy to do (website to advertise business), sometimes rather more difficult (we want a nuggetorium)
It has to explain what I did in a way which is both impressive and convincing (and also true).

And I’m really not enjoying myself

Time breakdown of modern web design

17 Jan 2007


piechart

It’s scary how accurate this is. For me, I’d want to drop the slice “Time spent actually designing anything” and replace it with “Time spent explaining the realities of html and css to distressed designer”

Favourite error message of the week

11 Nov 2006

,


‘Subtitle – Study Programming and Learn New Things About Punctuation

This week, when running a Php script, I got the error message:

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

After the “what!” reaction, I looked it up (remember, Google is your friend) and found that PAAMAYIM_NEKUDOTAYIM is Hebrew for a pair of colons.

It’s very nice that there is a word for a pair of colons (:: is used to access a static element of a class, so it can be used), but I feel that I am rather unlikely to use this term in casual conversation, or even in geeky programming-type conversations. I wonder if developers who have English as a second langauge have similar problems with the more standard and less esoteric error messages.

I’m also reminded, but not in a particularly nice way, of my first job where I wrote code for a Geac 9000 library computer in a language called ZOPL (ZOPL stands for “Version Z, Our Programming Language”). The guy who’d written the ZOPL compiler had obviously been a Pink Floyd fan and some of the error messages reflected this.

Debugging like snails

18 Oct 2006

,


‘My golden rule : Go slow. Don’t rush. Do one thing at a time.

On nuclear-powered subs, there’s a brass bar in front of the control panel for the power plant. When status alarms begin to go off, the engineers are trained to grab the brass bar with both hands and hold on until they’ve looked at all the dials and indicators, and understand exactly what’s going on in the system. What this does is help them overcome the temptation to start “fixing” things, throwing switches and opening valves. These quick fixes confuse the automatic recovery systems, bury the original fault beneath an onslaught of new conditions, and may cause a real, major disasters. It’s more effective to remember to do something (“Grab the bar!”) than to remember not to do something (“Don’t touch that dial!”)

Debugging: The Nine Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems

Weblog Style

2 Sep 2006

,


Well overdue – but I’ve finally reworked the wordpress templates so this weblog has the same style and layout as the rest of my site. It hasn’t taken that long, an evening, but there are so many other things on the to-do list which take precedence, especially if they are for other people.

The site design is by Kuldeep Salhan, not me. Design is something I’d far rather pass on to someone else – I have no visual flair and don’t enjoy faking it.

Client does not support authentication protocol requested by server

1 May 2006


I’ve been bitten by this one when trying to maintain different sites with different versions of php / MySQL.

Basically, user authentication for the later versions of MySQL server (versions 4.1 and above) has been improved and it now uses a default password hashing algorithm that is incompatible with older clients, including the standard PHP mysql extension.

The work-around is to reset the MySQL password to pre-4.1 style for all the accounts which connect via php

SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

However, the mysqli extension (short for “mysql, improved”) which comes with Php5 is compatible with the improved password hashing and no special steps need be taken.