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.

Sunday, 30 September 2007

MySource 4.0 WebDAV update

In a previous post, I mentioned some WebDAV improvements that I was thinking of implementing in MySource4. I've finally got around to trying some of them out, with positive results. The improvement I'm currently making to MySource4's WebDAV server is the ability to add files and folders.

Adding this feature was a lot easier than I thought, but the functionality it provides is much more impressive. I'm now able to drag files from my local machine into the WebDAV folder. I can also drag entire folders and have them imported along with their sub-folders and files. This makes mass-importing of files and folders as easy as copy/paste and is going to be an important part of any document management system.

The files and folders that are imported exist only in WebDAV and are not imported into MySource4 because I can't trust most WebDAV requests. When an administration interface is added to MySource4, I'll put something into it that allows the changes made in WebDAV to be committed to the MySource4 system. For now though, all imported files and folders can be viewed and edited by all editors using the WebDAV interface, so it works sort of like a staging area.

As much pain as WebDAV has caused me in the past, I've fallen deeply in love with it again!

Friday, 28 September 2007

php|architect on PHP_CodeSniffer

The guys at php|architect have had a quick chat about PHP_CodeSniffer in their latest newscast, hosted by Sean Coates and Paul Reinheimer.

One of the things they mention is that it would be great if PHP_CodeSniffer could be integrated into common editors. At Squiz, the MySource4 team already has PHP_CodeSniffer integrated into JEdit using a web service and a JEdit plugin that we wrote, and into TextMate using their built-in script plugin. Integration with other editors is something I'd like to look into further after the first stable release.

Monday, 24 September 2007

PHP_CodeSniffer 0.9.0 (beta) released

I've just released PHP_CodeSniffer version 0.9.0. No bug fixes were included in this release, but a couple of great new features made it in.

I've talked about the new Zend coding standard (including the Zend Code Analyzer sniff) before but there is also a long awaited feature that made it in; config options. Config options allow PHP_CodeSniffer and its standards to use persistent settings across runs. The most useful of these is the ability to set the default coding standard that PHP_CodeSniffer uses.

You can view the full changelog, and download the release, on the package download page.

Tuesday, 18 September 2007

Web 2.0 ... The Machine is Us/ing Us

As part of his Web 2.0 talk at the Matrix User Conference, JP showed quite a clever video about how the web is changing. Even though the video has received close to 4 million views, I hadn't seen it before. If you haven't either, here it is:

Screen Reader Simulation

If you have ever wondered what it is like to use a screen reader, this screen reader simulation may help you understand how hard it can be to navigate a site without seeing the content. Yes, it is a simulation so it is not perfect, but it will give you an idea.

What did I learn? Among other things, vertical bars may look cool between menu links, but I wouldn't want them there if I was using a screen reader!