@madpilot makes

The important things…

It is important to step back sometimes, and to look at what is going on. It is all too easy to become completely immersed in things in what is going on in your own life, that you forget how lucky you really are.

Today, I went to the launch of the Breast Surgery Gallery – a system that was developed by a uni mate of mine, Patrick MacQuillan as his honours project a couple of years ago. My honours supervisor (David Glance) was Patrick’s supervisor, and he asked me to do a quick re-design for their website before the launch today, which is why I was invited.

It was quite strange – as we walked into the offices, we noticed their was only two other guys there – the rest were woman. Now nothing was explicitly said, but it is pretty safe to say that a majority of the woman there (If not all) had been affected by breast cancer at some point in their lives.

As I was standing there, listening to the presentation, it hit me that these woman have had to deal with something that I could not even begin to fathom. Yet, they were here smiling – genuinely happy to see each other and to witness the official launch of a product that is actually helping people.

David, who has worked in large software companies for many years said something very profound (Maybe more so when you think about it) – he said: it was good to see a piece of software that is helping people.

We have all probably thought that a system we were writing was going to help someone, but not in the same way as this one did. The stuff that we write day-to-day will probably make someones work day more efficient, or allow them to shop more convienently – ironically the sort of stuff that in the whole scheme of things doesn’t really matter. This software was playing a roll in easing the pychological pain of life changing and life saving surgery, helping the suffers on the road to recovery.

It really isn’t often that software does that…

Design Patterns in PHP

I was going thorugh the posts from my old, now-defunct blog, seeing if there was anything I could bring over here — it is amazing how much can change in a year. There was an article I wrote about over use of cool techniques. In that article, I made mention to some new fangled technique called “Design Patterns”. At that point, I had no idea what they were and frankly couldn’t care.

Well, after being forced to look at them more closely for a uni assignment, I’m kind of a little hooked.

Design patterns are abstract solutions to common problems. Huh? Yeah, that is what I said. Many programmers strive towards code re-use. Design Patterns encourage thought re-use. Why re-invent the wheel? And because they are abstract (i.e. no code), they can be “ported” to different languages easily.

The Gang of Four introduced 23 of the things. They have put the challenge out for the discovery of more, and they haven’t been too successful as it is believed that almost all problems can be broken down to fit a composition of these rules.

To implement many of these design patterns correctly, you really need OOP features such as Abstraction and Interfacing. As I have pointed out many times, PHP4 doesn’t have these. PHP5 does. However! if you think about it, you can still use design patterns in PHP4 — you just need to be a little bit careful.

I won’t go through ever design pattern just now, but, I’ll outline one, and maybe add to them in the future. [By the way — an awesome book to use for getting your head around design patterns is “Head First Design Patterns” — look it up on Amazon]

The Stategy Pattern

Programmers often get into the habit of extending classes to change functionality — maybe because it is the easiest OOP function to understand. It can lead to problems though when you need to change implementations in a base class. I’ll use an example from a system I was writing the other day: the ubiquitous PHP email sender. The job I was doing required two types of email to be sent — a run-of-the-mill text email and a text email with an attachment.

Because I’m always trying to build my code libraries up, I decided to create set of classes that will do the job. Now, pre-design patterns, something like this may have happened:

Possible Email Class design using extension

Nothing wrong so far, but what happens if we want to add a HTML email? We could probably add another class below the attachments, because the HTML component is an attachment I guess, so we add the HTML file as one of the attachments at design time. This isn’t a great solution though, because one of the necessary bits to a HTML email is the HTML content, and you could theoretically remove it. How about we add another variable specifically for the HTML copy? That would also work, but what if the client decided that they wanted to select between HTML and text emails dynamically at run time? You would end up with something like this code wise:

switch($mailType) {  
  case “text”:  
    $email->setBody($text);  
  break;  
  case “html”:  
    $email->setHTMLBody($htmlText);  
  break;  
}

(This is a bit of a contrived example, so run with me here)

now what happens if you want to add another type of email? You have to modify the case statement and test the whole thing all over again. Everyone hates testing – especially code that you know used to work that you had to change. Two keywords: CHANGE and TESTING. Minimise both and we as programmers are happy.

Now my solution was to create a class that has everything an email needs – To, From , Subject and a repository for headers (Plus a few other bits and pieces, which I won’t mention to reduce clutter). It also has a function called send(). Wow, ground breaking. Where the design gets a little strange, is there is another variable, called $emailType. This variable stores reference to a class of type EmailType (Well it pretends to, PHP4 doesn’t support interfaces). So, any class that implements EmailType can be stored in that variable. One of the abstract classes (again, let’s pretend it is abstract, PHP4 won’t understand) is the createMessage() function. This is where the magic occurs…

Each class that implements that interface know exaclty how it message needs to be contructed. The base email class doesn’t care – as long as it gets a string to tack on to the email it is happy. The creation of messages is de-coupled, meaning you can create a new email class without changing any exisiting code (As long as it implements the interface correctly).

This is an implementation of the strategy pattern!

Formal Description [Ganf of Four]: The strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangable. Strategy lets the algorithm vary independently from clients that use it.

Which is what we just did… More on design patterns later.

Dead-man walking… bar the 11th hour reprieve.

It would be pretty safe to say that PHP is the language of choice for freelance developers and boutique designers. I suppose that this stems from the fact that is freely available, easy to set up and and easy to administer, which results in almost every web host (in Australia at least) running it. In fact, most hosts over here ONLY run PHP.

It would be interesting to see why ASP.NET hasn’t got more market penetration than it has – as much as I hate to say it, I’m putting my money on the fact it costs money.

CGI/PERL scripts are quickly fading away into obscurity – I remember when they were the only choice you had. It’s a security and maintainence thing. RIP mod_perl.

ColdFusion support over here is Oz is virtually non-existent. There are two hosts here in Perth, although it still seems popular in government and places that host their own servers.

New, funky languages such as Python and Ruby are still in their minority. From a configuration stand-point, Python is no better than PERL. It is still effectively a scripting language that has been extended to work with the web. At least PHP was specifically designed as such. Ruby is too new and support intensive. I hope that this changes. It looks cool (Although, I don’t like the syntax – I’m a fan of the curly bracket. So shoot me).

It seems that PHP was in the right place at the right time. When it arrived, dynamic web was still in it’s infancy – you had PERL and that was it. It allowed pretty complex systems to be built easily and cheaply (Sure, Coldfusion and ASP were around then, but were usually out of reach of the tinkerer), now it has so much history, no one wants to let go.

So we are left with old-trusty PHP…

Now, don’t get my wrong – PHP has treated me well. In fact, up until recently, PHP counted for 95% of the coding that I did. But, the lack of some object oriented features urked me – in particular exceptions and interfaces. It is very difficult to implement design patterns properly without the ability to abstract, overload or interface.

Now before any of you point out that PHP 5 has implemented most of this stuff, let me cut you off at the pass. I know PHP 5 supports many of the thinks that I’ve been waiting for, but I’m still stuck using PHP 4 for day-to-day work. Why? BECAUSE YOU CAN’T RUN THEM BOTH AT THE SAME TIME – well, not easily anyway.

I’ve been working with the ASP.NET 2 Beta for the last couple of months and it has no problems co-existing with ASP.Net 1.x, all you do is change a setting in IIS and you are away. Why then, do you have to jump through so many hoops to get PHP 4 and 5 to co-exist? It is for this reason, that most web hosting companies will not support 5 for a long time. From an economic point-of-view, they would be stupid to. Most applications run on 4. Not all of these applications will run of 5.

I have come up with a work-around, which is a pretty neat solution (I’ll present it later on) – it does require two different apache binaries to run and is a bit of a hassle to setup, but it does the job quite well (It would do it even better if I had more than one IP address), but I shouldn’t have to use work arounds.

Perhaps we will be left stifled by the shortcomings of PHP 4, at least in our bread-and-butter jobs, for a while yet. Perhaps one of the “killer” frameworks will eventually hit critical mass and knock it off it podium. Then again. Maybe not…

Blog number 1 Part II

Talking to the folk at Port80 tonight, I have been re-inspired to start blogging again. This may have something to do with all of the excitement around web essentials 05 (Which I missed – Phooey!). You see all of those lucky enough from Perth to go, have gotten me even more excited about the web industry, and I want to contribute back. So in a way you have Miles, Kay and Adrian to thank for this… he he he.

This blog will mainly be work related. Some mis-guided ramblings I suppose, but that is what blogging is all about isn’t?

I was amused to notice that the last time I started a blog was almost exactly one year ago (10/10/2004 to be exact). The reasons I did it last time surely had to do with avoiding work on my thesis. Ironically, I have another thesis to hand in in a couple of weeks – similar topic different degree… Looking into Gestalt theory again, but this time, I’m adding a part about remote usability testing. I’ve written a cool little AJAX based data logger, which I might atlk about another time.

Anyway – I’m going to try to get some sleep :)

About Me

Hi! I’m Myles. I’m a Melbourne-based software engineer and product designer.

I have a background in both frontend and backend development and I have a keen interest in product, design and business.

I hold a strong belief that everything an engineer builds interacts with a person in some way - I want to understand that interaction and make it better.

I believe developers are worth more velocity points on a card wall. They should be included in the whole design process. I want to work in iterative multi-disciplinary teams.

I have a strong interest in IoT development, in particular the ESP8266, the Thread protocol, 6lowpan and 802.15.4. I’m currently automating my house.

I’m a co-author of “Build Mobile Websites and Apps for Smart Devices” (Published by SitePoint).

I’ve also spoken at a number of International Web conferences, including Web Directions and Edge of the Web on the topics of Javascript, Mobile development and OAuth and OpenID.

You can find me on Mastodon and Github

Previous