OOP Articles on Think Vitamin

I’ve been working on a series of articles for Think Vitamin, the Carsonified blog, about OOP in PHP5. In fact I’m wildly excited about this, partly because I love to write and partly because its such a cool site to write for! The first two installments are now live:

  • Getting Started with OOP PHP5 – which is a very gentle overview of why OOP is such a buzz word, and shows off some very simple examples on how to begin and what the terms mean
  • Getting Started with OOP PHP5: Part 2 – a follow on post showing constructors, static properties and methods, and also looks at how PHP handles objects.

None of it is rocket science but these are important topics often skated over by writers wanting to get to the complicated bits! Hopefully these posts bridge the gap between the very dated introductory PHP content that is still lying around on the web and the tutorials about shiny new stuff that are more typically found elsewhere. The community over on Think Vitamin is great, the comments and retweets have been very constructive and I’m very excited to be involved.

Publications

I find I’m writing for a few outlets other than just my blog these days and often want to refer people to that content as well, so I’ve added a “Publications” page, linked from the left hand sidebar. This will keep up with the articles I’m posting elsewhere, interviews, and anything else along those lines, all in one place.

Speaking at PHPWM: April 6th

Next week I will be making the trip to my original home town of Birmingham to speak at the PHP West Midlands User Group, on 6th April. They are an active user group and although I haven’t managed to organise myself to attend their meetings before, I do keep meeting their members at other technical events so I know they are a good crowd and I’m looking forward to this! My talk will be “SVN in a Distributed World” – looking at the features of SVN, of the distributed source control solutions, and thinking about whether SVN is now an outdated technology or whether it is still a good choice for source control.

Hope to see you there!

Ada Lovelace Day 2010: Mrs Maginnis

This is a post in celebration of Ada Lovelace Day, recognising women in science and technology. Last year I wrote about Kathy Sierra for Ada Lovelace Day; this year my subject is someone much closer to my own life.

I’d like to write about someone who influenced me greatly – in my choice of study and in my attitude to the gender imbalance in that area and in the industry in which I now work. Mrs Maginnis taught me advanced maths when I was 16-18, and making decisions about my next move. I was educated at an all-girls grammar school, which in some ways was an advantage. The experience of those all-female maths classes taught me a lot about how different women are when they meet their individual challenges in the company of one another.

The classes were very tough academically (as they should be!), and I did struggle during the course. At the start of the summer holiday, Mrs Maginnis handed me a textbook with a list of questions to try, and her phone number. All summer I wrestled those questions, with the occassional phone call for help. I went back to school, completed the year, and left the following summer with two A grades in A-level maths – undoubtedly because of the help and support I had been given by this one teacher. Those two A grades landed me my first choice of university place – I thanked her and off I went.

However, the strong influence of this character has stayed with me long since the memorable day I opened the results envelope. I was headed for a course in Electronic Engineering and Mrs Maginnis had been a Mechanical Engineer herself and I think had a good idea of what lay in store for me. The thing is – I was educated entirely with women … I genuinely did not know that there were subjects that girls just don’t do. So when I arrived at university with my academic grades from the all-girls school, I was confronted by a course that was 95% male and contained mostly people with grades at least as good as mine and usually including more practical subjects such as Electronics, which I hadn’t had the opportunity to study. So it was a struggle from that point of view.

The teacher who had, on paper, taught me maths, had in fact taught me so much more. Even now I sometimes remember stories, anecdotes, and advice that all drifted across the classroom along with the hyperbolic functions and calculus (which is a much more distant memory now). She had been an engineer herself, and through her stories she showed us all how it would be done, something on what to expect and some tips on how to handle it. Even now I don’t think I’ve had a stronger female role model for industry – and she managed all this from academia, when I was a teenager. So – I raise my glass to Mrs Maginnis. Thankyou for all you taught me.

GETting RESTful collections – may I filter?

At work at Ibuildings recently, I’ve been teaching some classes on web services, and its a topic that I’ve spoken about once or twice at conferences. But something has always bothered me, so I find myself in the unusual position of blogging a question.

RESTful collections

So, when you are retrieving information from a RESTful service. You have two options: retrieve a specific resource, whose URL you know; or retrieve a collection, which may contain a list of resources. I’ve also seen some nice ways of filtering collections, by creating kind of “sub collections” or “views”, similar to what twitter does with the URL of lists, for example http://twitter.com/dpcon/speakers10 which is like a filtered list of twitter users.

What if I want to search and sort?

Is it RESTful to add GET parameters to a collection in order to add functionality such as filtering, sorting, or pagination? What I have in mind is a URL that looks something like this:

  • http://example.com/users?orderby=firstname&start=0
  • http://example.com/users?start=0&limit=25
  • http://example.com/users?active=1&orderby=join_date&limit=12

This is what I would do with a search results page in a web application, and I use the same approach to web services which works really well and I recommend it to everyone! But is it RESTful?

I am also wondering where OpenSearch would fit into the answer for all this, I only noticed it recently but the more I look at it the more I think it could be an interesting addition!

Thoughts, links for me to RTFM, and all other additions are welcome in the comments box :)

Big Bed Cushions

This week I finally got around to making the big cushions for our bed. We do have some but they were cheap and are now old – and I reallocated Kevin’s onto my office chair about a year ago. Since we do often read or use the laptops in bed, cushions would be a good thing to have, but I just didn’t have the time to make them! Work was less crazy in February and I found I had the mental space to think of these things, so I bought two big fluffy cushions, and dug out the fabric I had left from making the curtains so that the cushions would match, and here they are:

New Bed Cushions

The cushions were 66cm so I cut two rectangles that were (66cm plus seam allowance) wide and ((2.5 * 66cm) plus seam allowance) long. Then I hemmed across the short sides (this was really fraying fabric, I should have overstitched everything before I started but I was too impatient!). They are simple envelope-backed cushions so I lay them on the floor with the right side up, folded the long sides at 33cm and then 99cm, basically you have a short end folded up and then the long end folded over that, with the seams showing. Then you sew up the sides and when you turn it the right way out – the short bit of the envelope is on the outside.

Dead simple but they match the curtains and they are lovely and soft – the fabric is plain sheeting too so nice and comfortable even in bed!

PHP London Conference: In Review

I’m really late with this post, but I wanted to write about the PHP London Conference which was held in London last Friday. The event was in a great venue and had hoards of people – this was my fourth year in attendance!! They do, however, have the longest twitter tag in history #phpuk2010!

This year I had the privilege of speaking at this event, although I was concerned that I had to stay coherent and alert right through to the graveyard slot at 4:30pm (conference organisers take note: I really am much sparklier in the mornings!). I kept myself awake by attending what I affectionately refer to as the “Ibuildings track” – with 4 speakers at the event, it did feel like a bit of an invasion by myself and my colleagues. In our defence I can only say that we are a pretty big local PHP employer and, as a developer, I’m happy to be working for someone who sends all their developers to these events, and even happier to be in the company of those other excellent speakers as colleagues!

My talk was entitled “Best Practices in Web Service Design” although perhaps “Things I Wish Web Service Creators Would Consider Before Writing Unclear and Unstable Useless And Frustrating Services” would have been a better title! I talked about web services in general, a bit about HTTP and the various service types, and also gave some general tips and tricks for writing good, stable services. In a bit of a break with geeky tradition, I then talked about services as a whole package, and how to deliver and document them in a way that helps users help themselves. If you are interested the slides are here:

http://www.slideshare.net/lornajane/best-practices-in-web-service-design

The experience was overall very positive for me, I haven’t spoken at this conference before and I was very pleased to be included. My talk went quite smoothly, with my nerves nicely hidden away (I’ve had issues with this lately), and I also avoided falling over either the curtain or the piece of screen that was carefully placed to trip unwary speakers! I’d like to thank everyone who came and asked questions afterwards, and all those who saw my talk and left comments for me on my joind.in talk page – it all helps me to do better next time, thanks and I’ll see you all next year!

Simple Database Patching Strategy

One problem that seems to need solving too often is how to keep databases in sync across different platforms, different developers working on a project, and deploying database changes along with code changes. There are lots of ways of approaching this, none of them are really excellent however and personally I tend to err on the side of simple being better. Fewer dependencies means a solution more likely to work on every platform (and no additional complications for the live platform). Usually this means patch files of some kind – here’s an outline of my usual approach. For the impatient:

  • add a table for meta data to the database, set a database version parameter to 0
  • export structure and any essential data (lookup tables, etc) into an sql file
  • for any changes, create a numbered patch file e.g. patch-1.sql, including the change and an update statement to bring the version meta data to match the patch file
  • store all of the above in source control
  • for bonus points, create another sql file with some nice sample data

Give the Database Some Version Awareness

Naming is completely changeable but mine looks something like this:

CREATE TABLE `meta_data` (entry varchar(255) primary key, value varchar(255));

INSERT INTO `meta_data` SET entry="version", value="0";

This new row will hold information about what patch version the database is up to. Every patch that is created will update this number so that it is possible to tell which patches have and have not been applied.

Create an Initial Data Structure

Firstly create a database directory for all these files to live in. This should be outside your web root but inside your source control project.

Take your database and dump just the structure of the tables using the –no-data switch to mysqldump like this:

mysqldump -u  -p  --no-data > create.sql

You will also want to populate tables which hold things like lookup values, country lists, that sort of thing, so that these are set up. People starting to develop with this project, or if the application needs to be deployed to somewhere new, can use this file as a starting point.

Create Patches for Changes

This is where the discipline element comes in – no direct edits on the database are allowed! Instead, write the SQL for your change and place it in the patch file, then run it against the database. If that sounds too much like hard work then copy/paste the SQL you use to make changes, or the SQL generated by whatever SQL tool you use, and place it in the file.

Every file must have its own incrementing version number in its file name, e.g. patch-1.sql, patch-2.sql etc. Within the file the version must also be updated to match, with a statement like:

UPDATE `meta_data` SET value="1" WHERE entry = "version";

Recommended Practice

Here are a few pointers on getting the most out of something like this:

  • Under no circumstances is it acceptable to edit a patch file that has been committed to source control. Someone might have run it already and you’ll confuse everyone completely.
  • Having matching undo scripts alongside the patches can be really useful in case a change gets deployed and needs to be undone.
  • Make a script to look up the database settings in the config file of your application, query the database for what version it is at, and run any outstanding scripts. This makes life much easier especially if you have large numbers of scripts (I’ve seen the patch numbers hit the hundreds)
  • A possible adaptation of this approach is to create patch files for use for updating a database, but to also update the install.sql file to make it correct at any point in time, this means a much shorter and easier setup time for new deployements/developers. The version awareness works in the same way regardless
  • Creating a sample database which creates a few records in each table can really help for development purposes – its quicker for people to get set up and attain a working system that they can make progress with.

I’m sure there are many improvements and variations on this theme of simple database patching, leave a comment and let me know what works for you and why!

Supermondays: Recap

Last night I travelled to the northeast of England to speak to a thriving technical community up there called Supermondays. They contacted me some time ago asking if I could get there to speak one Monday, and last night was the night! It was a very civilised gathering, with sandwiches and cups of tea, and using a lecture theatre at the university for space. As a speaker the best thing about this is that its a space designed for addressing people in, unlike most user groups (and indeed conferences!) where two steps away from the lectern sees you standing in the dark, falling off the stage, or getting projected on to. Last night was a different story with lots of space to wander, slides projected well above me on the wall so everyone could see clearly, and relatively good acoustics despite no amplification.

My talk was entitled “PHP and Web Services: Perfect Partners” – the slides are on slideshare if you want to take a look. There was also a talk about android development by Alex Reid, including a live coding demo which went surprisingly well! Judging by the various events that were plugged and discussed on the night, at the main event and in the pub afterwards, this is a diverse and vibrant technical community – so if you are in the northeast, get along to Supermondays!

Open Office Presenter Console

I’ve been having issues with the presenter console on both my ubuntu machines since upgrading to Karmic (9.10). One is a Thinkpad T400 running kubuntu and the other is an aspireone netbook running ubuntu netbook remix. Neither wanted had a working installation after upgrade and I couldn’t get the plugin installed using the open office plugin manager.

I discovered that this plugin is now available through apitude – simply install the package openoffice.org-presenter-console and it should all work splendidly! I use the presenter console when I am speaking (which is quite often) to show the time and the upcoming slide, its a great tool.

An iPhone App for Joind.in

Recently I’ve been doing some bits and pieces with the open sourced event feedback site joind.in, including some work on its API to facilitate development of an iphone app. As a conference attendee, speaker and organiser, I use this site a lot for the various events that I am involved with and its a great asset.

My boyfriend Kevin was thinking of developing an iphone app, mostly to find out more about the technology, and I suggested he take a look at the API for joind.in and consider building something on that. The joind.in project belongs to enygma, a.k.a. Chris Cornutt from phpdeveloper.org and he has the code available on github – so we grabbed it. The API wasn’t previously used by much so we were able to tidy it up a bit and then consume it from the iphone to suit our needs. Chris has accepted my alterations to his existing project with grace – even when I’ve totally broken the live site with them!!

The joind.in site is a classic MVC setup and the API already existed within the application. It is implemented with a separate set of controllers for the various actions supported by the API, which all inherit from a controller which handles the output formats etc for the XML and JSON responses. It isn’t the world’s best API but its perfectly sufficient for the task at hand – I intend to write some examples for using it but until then you can read this post from Derick about how he used the joind.in API to pull in comments on his talks onto his own site.

The app itself has the core functionality of joind.in that an attendee would want in his pocket at an event. The events and their details are there, along with the talks at each event. Attendees can leave comments on the various talks and socials, and these can be browsed in the app as well. To give you a little taste of the app, here are some screenshots:

img_0023 img_0024 img_0025

If you have an iphone or ipod touch and you’re attending an event any time soon, then download the app – its under “utilities” in the app store. Comments, suggestions, bug reports and feature requests are all gratefully received (no promises about fixing/implementing them but we’ll do our best!). Our app went from submission to approved in 3 days which is very fast – thanks apple!