A bit like a House

I’m often wracking my brain to come up with good analogies to explain why we should develop things one way rather than another or to try and explain a development strategy to non technical people. Sometimes these people are Clients, sometimes Employers, often Designers (you get the picture).

But the question remains how best do you explain (often slippery) concepts to people who haven’t got a clue what you are talking about, and without resorting to Jargon or Technical Terms?

Lately I have spent a lot of time figuring out how to evangelise various Frameworks; or actually just the concept of a Framework. Specifically I want to spend most of my time at work developing in CakePHP not jury rigged and ad hoc or home brewed libraries built by either myself or others. I think we’ve all been there… very early on as a developer you come to realise that you need organisation. You start gathering together useful classes and functions, maybe you come up with naming conventions.

It’s great your development speeds up, you learn a great deal along the way. Your boss is happy, but then for your next project they want you to do something just a little bit different. You start off no problem, I’ve got all this code, it’s great – it’ll be done in no time… except it isn’t because your system can’t bend and you are stuck writing so much code to deal with the exceptions that your benefits seem to evaporate.

A good framework seems to provide a solution – you get to take advantage of a lot of very smart people, you get the benefit of a community, you learn good practice, hopefully a lot of the mistakes and dead ends have already been avoided. In fact for me probably the worst thing is when I have to work back in mud of projects and systems that have just accumulated over years, the sinking feeling…

I think they key point is that there is a sense of an overview – that everything has a place. The framework buzz at the moment is all about MVC based systems – they have that organisation. What is nice is that looking at something written in say CakePHP or Code Igniter it’s usually pretty obvious what is going on, but even something written in Rails or Django will have familiarity due to the similar structure (my Ruby and Python skills are essentially non existent).

But back to my analogies. I live in a beautiful old cottage that is probably a few hundred years old, but some of it is made of brick, some of it is stone. One wall (we believe) is made entirely of mud (Cobb), there aren’t really any foundations and the house is listed that means we can’t fiddle about too much. Over the years people have added water and gas and electricity but it would have been so much better if they had been planned in from the start.

Of course, if you build a new house you can make something amazing (as long as the architect’s OK).

XAMPP and the PHP CLI

Like a lot of people I do most of my development work on windows PC and locally run a web a server and database. Like a a lot of people I just downloaded and installed a server bundle. For the last few years I have used Apache2triad and it has generally been pretty painless, but I’ve recently been forced to abandon it. Unfortunately the development seems to have been abandoned about 2 years ago.

The reason I abandoned Apache2triad was PHP versions – I wanted to do some work with Google Base using the Zend Google Data Library which required PHP 5.1.4+.

Looking around at the various bundles I decided to go with XAMPP – a lot of people seem to use it and it seems to get pretty good feedback. I won’t say the process was entirely painless (it took a couple of goes to get everything up and running) but eventually it all seemed OK.

The fun started when I decided to do a bit of baking (generating scaffolding code for my CakePHP app from a command line interface). Nothing worked.

Looking into it I discovered more than I wanted to know about the PHP Command Line Interface (CLI) which I had happily used for years with no idea it actually existed, having assumed it was just there as part of PHP.

After a lot googleing and a lot of trial and error I got it all working again and this is how I did it.

My environment is Windows XP Pro Service Pack 2 with XAMPP installed on E:/

  1. Downloaded the latest version of PHP and replaced the entire contents of E:\xampp\php\.
  2. Added to the E:\xampp\php to my environment PATH.

At this stage PHP CLI wwas now working but there were nasty errors e.g. I was uanble to connect to MySQL from scripts. I discovered that this is because PHP CLI uses a different php.ini file to regular PHP.

To fix this I copied my php.ini from E:\xampp\apache\bin\php.ini (the default XAMPP ini file) to E:\xampp\php.

I then checked the PHP CLI again using php -v at a command prompt. There were now about 6 errors displayed, concerned with modules that could not be loaded or found. I believe that these concern modules just that aren’t meaningful in CLI mode. So I went through my new php.ini in E:\xampp\php and commented out the directives that were causing the errors until PHP CLI ran without errors.

Finding overlapping dates and times in MySQL

Quite often you end up in situations where you are required to check and see if one time period overlaps another time period. Probably the most common situation this occurs in is when you are building a booking system – be it for tables or cars or rooms.

You have a series of entries in a database with a start (date)time and an end (date)time and before adding a new record you need to check that it doesn’t overlap with another booking.

The solution is fairly simple but I always end up making a quick diagram on a piece of paper to check.

Time overlapping diagram

As you can see two time periods can either be sequential (i.e. there is no overlap at all) or they can overlap in one of four ways. Put this into a diagram and the solution becomes pretty obvious.

There is an overlap if end_time_1 > start_time_2 AND start_time_1 < end_time_2

Time start_1 start_2 end_1 end_2 end_1 > start_2 start_1 < end_2
1 09:00 08:00 11:00 10:00 true true
2 09:00 10:00 11:00 12:00 true true
3 09:00 08:00 11:00 12:00 true true
4 09:00 09:30 11:00 10:30 true true
5 09:00 07:00 11:00 08:00 false true
6 09:00 12:00 11:00 13:00 true false

An example SQL query would be something like the one below but make sure your datetime formats are correct – in MySQL the default format is YYYY-MM-DD hh:mm:ss


SELECT * FROM bookings WHERE room_id = '" . $room_id . "' AND ((date_end > '" . $start_date . "') AND (date_start < '" . $end_date . "')) ";

The above query will pull back the records where the times overlap.

blinks.org.uk

Lately I’ve have taken a little bit of time out from Art-Thing and have been working on a smaller side project called www.blinks.org.uk

I’ve been using this as a bit of a test bed for various aspects of Art-Thing but it is also a fun little project in its own right. AND even better it should be ready very soon, it is a directory of UK businesses and services with a pretty flat structure based on tagging and regions. Fast, easy to use and fun (if a business directory can be fun).

The site is almost ready to launch and the whole process from the first ideas until now has been very quick – it is built in CakePHP 1.2 and jQuery which make coding a pleasure again. It’s also fun to do a bit of design for a change instead of just the stuff under the hood.

Here is a sneak preview:

blinks.org.uk

If you own or manage a business in the UK why not sign up for FREE with blinks.org.uk and see how it can help your business.

blinks.org.uk is a brand new directory of businesses and services based in the UK.

Every entry in the directory is approved by a real person and businesses have to provide their actual address so the directory is completely spam free and only contains quality listings.

  • Link back to your website (great for SEO)
  • Add a description of your business or service
  • Add an image or company logo
  • Update your entry whenever you want
  • Add you business or service to multiple categories
  • Add tags (keywords) – that are right just for you
  • Automatically show your location on our map

Finding a business in the UK - made simple