Sunday, 28 October 2007

CruiseControl and PHP_CodeSniffer

Manuel Pichler has written a nice article about how to use PHP_CodeSniffer in the continuous build system CruiseControl. He uses PHP_CodeSniffer's XML output format and transforms it into a format that the Checkstyle Ant task can use. To quote:

This PEAR package provides a variety of pre defined coding standards like PEAR, ZEND etc., a small cli script phpcs to run PHP_CodeSniffer against your code and as best it provides an XML output generator. This output is not compatible with checkstyle but it is simple to transform into the Checkstyle format that is supported by CruiseControl. You can use the following stylesheet to transform the PHP_CodeSniffer output for your CruiseControl installation.

Manuel provides the complete XSLT and commands for transforming the XML, as well as the Ant build file. I gave the transformation a go myself, which turned this:
<?xml version="1.0" encoding="UTF-8"?>
<phpcs>
<file name="temp.php" errors="5" warnings="0">
<error line="2">Missing comment</error>
<error line="13">Missing tag</error>
<error line="13">Missing tag</error>
<error line="13">Missing tag</error>
<error line="13">Missing tag</error>
</file>
</phpcs>
Into this:
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
<file name="temp.php">
<error line="2" severity="error" message="Missing comment"/>
<error line="13" severity="error" message="Missing tag"/>
<error line="13" severity="error" message="Missing tag"/>
<error line="13" severity="error" message="Missing tag"/>
<error line="13" severity="error" message="Missing tag"/>
</file>
</checkstyle>
(error messages shortened to fit)

Creating a new report format for PHP_CodeSniffer to match Checkstyle would be easy, but I haven't managed to track down any good examples of Checkstyle's XML output yet. I've put that on my todo list.

Thursday, 25 October 2007

Making Ajax Work with Screen Readers

I recently came across this article about Ajax and screen readers. To quote:

The Web Accessibility Initiative's Protocols and Formats working group directly address the issue of making rich Internet applications accessible, and we borrow some of their concepts to investigate methods of ensuring that Ajax applications work with leading assistive technology products.

The article does more than just offer helpful hints. It also explains some of the inner workings of screen readers to help web developers understand why the techniques are required. A couple of Ajax form examples are also provided.

Tuesday, 23 October 2007

All PEAR packages now checked with PHP_CodeSniffer

Thanks to some great work by Christian Weiske, PHP_CodeSniffer has been added to the PEAR QA framework. So now, all package developers can visit the PEAR QA overview page and see how many coding standard errors and warnings they have in their package.

Here is the full announcement:

Hello all you pear developers,

Our quality assurance suite now utilizes our great package PHP_CodeSniffer to generate reports about each package's coding standards compliance.

You can get the full overview at
http://pear.cweiske.de/overview.htm
Just click at the CS error/warning count to get a detailled listing of problems in the package.

Please also note that we're currently evaluating to extend and clarify the standards. See my last email to this list or http://wiki.pear.php.net/index.php/CodingStandardsChanges

As always, comments are very welcome.

I'm also pretty happy that someone has decided to review the PEAR coding standards, as there are a few gaps that need to be filled in and some conflicting standards that need to be clarified.

Saturday, 13 October 2007

My Squiz Story

I read a question on LinkedIn about "Your Story". It got me thinking about what I have achieved so far, so I've decided to write it down. Some of the specifics might be a little off, but here is "My Story" so far.



I started at Squiz in December 2001 after 2 years of a computer science degree at UTS. That particular degree encourages students to work full-time during their third year and come back to complete the 3-year degree in their fourth year. I have to admit that I was pretty nervous about going out into "the industry" after only 2 years of computer experience, but it turned out to not only be a great career move, but also helped greatly during my final year at uni.

I had been playing around with a personal web site and loved the idea of working with/on the internet full-time, so the job description for Squiz was very appealing. Both my (now) wife Deb and I went for the 2 positions being offered by Squiz, as did a lot of other UTS students. After two interviews, I was offered a position. Deb missed out, but ended up getting a .NET job a couple of months later. Incidentally, she now works as a senior trainer and documentation writer at Squiz. The other position was given to Daphne Chong, a mate from uni, so that eased the nerves a little.

During my second interview I was introduced to "Agi", who I assumed (by the name) was a burly seasoned Eastern European development lead. Steve "Agi" Agland was actually a skinny young PHP developer still completing his computer science degree at UTS. Agi was to become someone I learned the trade from, a good friend, and eventually best man at my wedding.

At the time, Squiz was a small company of about 20 people. Everyone worked at "the church" on Jarret street and there was only one office; Sydney. I was one of about 6 developers who not only wrote the code for the CMS, but also did all the implementation and provided client support.

On my first day, I was given the task of cutting up a design (the first of many). That involved taking a PSD file, determining the table layout (it was the bad old days of table-based design), cutting out the individual images for the cells, and coding the HTML. I had one problem; I didn't know how to code a table in HTML.

My complete lack of HTML knowledge wasn't all; I had been "coding" in PHP for 2 weeks. I had done Perl before, but I was employed to work on a large PHP Content Management System (MySource) which involved writing a lot of PHP and HTML.

Luckily for me, I was paired with a great teacher; Blair Robertson. Blair had started at Squiz the year before, also during his 3rd year of a UTS computer science degree. I remember watching him show me how to cut up this design and thinking to myself "how can this guy be so good after just 12 months?".

Blair was certainly someone to look up to and I aspired to be as good as he was. When I finally got my hands on MySource, then still reporting a version number of 0.85, I tried my best to learn it inside-out. I went home (a 2 hour trip) and worked on it all night. My greatest achievement at the time was adding colspan support into the bodycopy. I remember porting the code to Matrix a couple of years later and still being challenged by the code.

I ended up doing a lot of work on MySource, and became a more senior developer at Squiz. Eventually, it was decided that our page-based CMS needed to be upgraded to an asset-based CMS, and as the most senior full-time developers (Blair had left to go back to uni part-time) Agi and I started work converting MySource. After a few weeks, we had files working as assets, but it had become clear that we needed to start from scratch.

A meeting at JP's apartment between Agi, Blair, JP and myself reached a conclusion that we needed to start work on a new asset-based product, which was to become MySource Matrix.

Blair came back to Squiz full-time in 2003 after completing his degree. He was tasked with creating MySource Matrix, and was the only developer assigned to the project initially. I had decided to stay at Squiz full-time and complete my degree part-time over the next couple of years. That decision turned out to be a good one. A couple of months later, I started writing the MySource Matrix WYSIWYG editor and eventually started working with Blair full-time on MySource Matrix, which was one of the best experiences I have had at Squiz.

On a side note, MySource Matrix was originally named Mortar (as in "bricks and mortar") by Blair. When I started on the project, we renamed it to Resolve (a name I still love). JP and the sales team decided that Matrix was the name we were to use, which didn't sit well with Blair and I. In fact, we hated it so much that we used "MySource" in all design area tags instead of "Matrix" (they were original "Resolve" tags) and changed the version tag to "MySource v0.1.1 (Matrix)". We put "Matrix" in brackets because we were treating it as a build name and decided that we would change it with each major release. That obviously didn't happen. Later, after renaming the product to Resolve FX (at Norton's pub one night, and in our head's only) we put a hidden code into the asset map that changed the MySource Matrix logo to a Resolve FX logo.

Eventually, our two-man team turned into four as we added Marc McIntyre and Dominic Wong to the team. Squiz was really starting to expand at this time, and we were shifted into the back-room of "the church", which is now the training room. Just before Blair left to move to the UK and help start the office there, we took a famous picture that marked the day we finally embraced our new product name. The picture depicts the four Matrix developers posing in dark glasses behind a backdrop of code from the Matrix movie. Each of us signed the picture with our favorite Matrix quote, except for Blair who couldn't help writing something about the pub. I've still got the framed picture on my desk.


From left to right: me, Blair, Marc, Dom
Click for larger image

Blair leaving moved me into the lead developer role at Squiz (Agi had left to work on the movie Happy Feet with Animal Logic). Squiz grew around the new product, starting our support and implementation teams, and eventually moving into other Australian states. The dev team moved to a new office on Elswick street, just down the road from "the church", which we quickly outgrew. We traded that office in for one on the other side of "the church", which is where the majority of Squiz staff in Sydney now work.

Just before leaving the Elswick street office, Marc and I started thinking about a new product; MySource4. We had a lot of great ideas based on the years of CMS experience we now had, and finally convinced JP to start a new project team.

We assembled a team of the four best Matrix developers and started work on MySource4. Marc was the team leader and I was the project lead. I worked with Marc on the system architecture but left the coding up to the other three. I was still leading the Matrix team, so I was pretty busy during that period. I was also unit head of the development team, so I had to start doing all those managerial tasks like approving leave, performing pay reviews, and hiring new developers. That was about the time I stopped doing any real PHP development.

I had started PHP at the end of 2001 and had stopped by 2006, only four years later. I was still going to be doing some work on development tools, like our unit testing and code sniffing software, but my full-time PHP role was over. It took some getting used to.

Everything kept ticking over until the present day. Squiz is going strong, MySource Matrix is going strong, and MySource4 is well on the way to becoming a revolutionary CMS (and PHP) product. I finally graduated from UTS in 2005 with a Bachelor of Science in Computing Science and 1st class honors. Marc and I started PHP_CodeSniffer, which was accepted into PEAR in 2006. I still work on PHP_CodeSniffer regularly to keep my PHP skills current, and do some work on MySource4 itself. I'm still the lead developer of MySource Matrix and am now Product Development Manager at Squiz. Deb and I got married in 2006 and are expecting our first child in January.

I'm looking forward to the future.

Friday, 12 October 2007

Puzzle in JavaScript

Scott Kim, one of the MySource4 developers at Squiz, has made good use of his JavaScript skills and created a puzzle application using jQuery.

This is a very simple sliding puzzle written in Javascript using jQuery library. It works with most of major browsers except for Safari admittedly due to my bad choice of mixing algorithm. Please enjoy your time and don’t do it too much. You might fall in love with Scott too much :)

Nice job Scott. It evens works smoothly on my 4 year old PowerBook G4. I think I'm in love!

Saturday, 6 October 2007

University of Malta chooses MySource Matrix

An article came through on one of my Google Alerts last week about the University of Malta using MySource Matrix to rebuild their web site. At the time, the new site was still undergoing final testing, but the University of Malta has now made it live.

The site looks fantastic, but it's also special for me as my mum's side of the family are all Maltese. I've never been to Malta, but I've seen some amazing pictures from my mum's recent trip back that make me hope I get there one day.

Congratulations to everyone involved in building another great MySource Matrix site.

Friday, 5 October 2007

Deleting folders in WebDAV

I was coding up support for the DELETE request in WebDAV and came across yet another difference between Windows and OS X. I had a good run of things "just working" on both operating systems, but I guess it had to come to an end eventually.

Let's say I have the following directory:

Images
|_ img1.png
|_ img2.png
|_ img3.png
When you delete the directory in OS X, the following requests are sent:
DELETE Images/img3.png
DELETE Images/img2.png
DELETE Images/img1.png
DELETE Images
When you delete the directory in Windows, the following requests are sent:
DELETE Images

Spot the difference?

I'd rather have a different DELETE request sent for each file and folder, allowing me to delete the temporary files along with the DB entries much more easily. Having said that, I'm not totally against "the Windows way". It is better for performance but it will leave a lot of temp files hanging around because the request would take too long if I went through and deleted each one. That's not really a problem because they will be cleaned up eventually, or reused.

Luckily, OS X sends the requests from the bottom up, allowing me to process both methods in the same way. So on OS X, temp files will be deleted; on Windows, they will not be.

It's not the individual processes that get to me. It's that fact that there are (again) two different ways of doing things.

...and don't get me started on Vista!

Implicit comparisons in PHP

Tobias Schlitt recently wrote a blog entry about the speed of PHP comparisons. In it, he mentions that using the === operator to compare types as well as values is faster than using the == operator to compare values only. This is something that has been known for a while and we've made it part of our coding standard for MySource4.

Yes, the performance improvement you get is minor, but even the smallest changes add up for a site with hundreds of thousands of page views a day. Think about how many comparisons would be done during a single page load and you'll see that even small improvements like this one start to become significant.

Something else he mentions is that comparing return values of functions is faster than using an implicit comparison. So, for example, this code:

if (isset($foo) === true) { ... }
is slightly faster than this code:
if (isset($foo)) { ... }

I'm not sure that the tests performed are accurate, but we don't use implicit comparisons in MySource4 either. Not because of performance but because the code is easier to read. Again, this is part of our coding standard and is enforced by the Squiz standard in PHP_CodeSniffer.

If you would also like to incorporate these simple changes into your coding standard, PHP_CodeSniffer is a great tool to help you enforce them and show you where you need to make modifications to your code. You can either use the included Squiz standard or incorporate the specific sniff, Squiz/Sniffs/Operators/ComparisonOperatorUsageSniff, into your own custom standard.