PHP and Annotations

After hacking together some code to solve an issue that came up on an IRC channel I’m up today about how to provide a URL mapping for individual methods — and keeping the responsibility in the method itself, I stumbled across addendum. Addendum implements annotations parsing for PHP and works by using the reflection API in PHP 5.1+. This allows you to add annotations which indicate to your framework which methods should be exposed to the web and which should be kept private. There are loads of other ways to do this (both dynamically and statically), but this is one way that may appeal to someone.

Book Read: The Pixar Touch: The Making of a Company

Just finished “The Pixar Touch: The Making of a Company” in record time (.. for me). Awesome book. I’ve been a fan of Pixar since I first saw Toy Story at a special presentation (.. it had the original voice actors, not the dubbed, Norwegian version) here in Norway in 1996. I still consider Toy Story 2 as one of the best movies ever made.

The Pixar Touch: The Making of a Company gives an unique view of the history of Pixar. As I started following Pixar more closely after that winter day of 1996, I had a simple overview of the situation up until now. What really impressed me was everything that happened up until the release of Toy Story, and as usual, all the random events that formed the great company known as Pixar today. If you have an interest in animated movies, business issues, great histories and great people, I’d really recommend reading this book. It’s awesome.

The mere fact that I read through it in just a few days when I usually spend a couple of weeks on a book is a good testament to that. I’m an even bigger fan of John Lassetter now.

New book: Why We Buy: The Science Of Shopping

What. Four. The number.

Kristian obviously has way too little to do while in Newcastle, UK, so he got challenged by his girlfriend to write a list of four items on several key subjects. And he challenged me to do the same. Bastard.

  1. Name 4 jobs I have had:
  2. 4 movies I could watch again:
  3. Name 4 places I have lived:
    • Trondheim
    • Fredrikstad
    • .. and that’s that.
  4. Name four tv shows I like:
    • West Wing
    • South Park
    • Numb3rs
    • Bones
  5. Four places I have been on vacation:
    • Hartford, CT, USA
    • Orlando, FL, USA
    • Jylland, Denmark
    • London, UK
  6. Four web sites I visit every day:

As I’m a cheerful fellow, I’m not going to challenge anyone. But I’ll leave a brief hint that it’s about time that Ole posts something in his blog again.

(Bonus point: The first time the category “Uncategorized” has been used with intention on this blog. This really is uncategorized.)

Book Read: The Bullfighter’s Guide

Just finished the book Why Business People Speak Like Idiots: A Bullfighter’s Guide today, after reading it off and on for the last week and a half. The book read very easily and while I probably need to read it again after a year or so, I’ve already tried to adopt to several of the good habits proposed in the book. While I feel that I usually get down to earth and try to communicate clearly in my E-mails, I’ve become much more aware of my weasel words and my use of jargon where none is needed. The short read means that the book communicates effectively, and I’d advice anyone who’s going to hold a presentation or write a business related memo or article to at least read it once.

Add it to your wishlist now! (I prefer linking to the original, american Amazon store instead of the UK one, as the US store usually is cheaper. The delivery takes a bit more time, but if you’re in Norway you order loads of books at the same time anyways because of shipping..)

New book: The Pixar Touch: The Making of a Company

Google Earth and Error Code 29

I finally installed Google Earth on my Ubuntu Intrepid installation at work today, but everything crapped out with a “Could not contact… Error code 29” error. Didn’t find any obvious solution at first, but deep inside a thread at the Ubuntu forums I stumbled across a post about how to fix Error Code 29 in Google Earth. The trick? Install lib32nss-mdns through apt-get, delete .googleearth and .config/Google/GoogleEarthPlus.conf, restart and be happy.

Worked great. Thanks Mr. / Ms. / Mrs. Melk79.

iTunes out of Norway?

Apple and the Norwegian Consumer Ombudsman, Forbrukerombudet, have been complaining about each other for quite some time now. The issue that has sparked the controversy is the locked format of Apple iTunes, where music is only available for Apple’s own platform (iPod). The Consumer Ombudsman demands that music sold in the iTunes music shop are made available in a format thatcan be used freely on other devices on the market. Apple had until the 3rd of november to comply with the demands, but have responded that they will not do anything to resolve the issue (Read the letter from Apple here). This has lead the case to now move up higher into the bureaucracy, onto the desk of Markedsrådet. This instance have the right to enforce laws and any decision made here will have to be followed by Apple if they want to keep themselves in the Norwegian market.

I’ve written a bit about the market for digital distribution earlier, and while iTunes have been a great way forward for introducing people to digital purchasing of music, I think that they’d get that position regardless of their use of DRM. They’ve done a few things to loosen up their tight DRM regime, but other providers, such as Amazon, has done a much greater job.

I’m glad to see that the issue is going somewhere serious here in Norway, and I fail to see this as a great threat to the online distribution in Norway. People have made the complaint that this will just lead to Apple pulling out of Norway, leaving our quite small market to itself. If that happens, then we suddently have a large market available for other online ventures, without the threat of Apple going after their market. Imagine the music distribution market in the united states if iTunes suddently decided to stop distributing music. Amazon would laugh all the way to the bank, other ventures would pop up all over the place, and the consumer would probably be better off.

If Apple decides to remove DRM, then it suddenly becomes a viable place for purchasing digital music here in Norway for me. If Apple wins we’re in the same situation as we are today, where they don’t respect the wishes of the consumer organizations anyways.

PHP Namespaces and the What The Fuck problem

As many people has discovered during the last days, some of the developers behind PHP has finally reached a decision regarding how to do introduce namespaces into PHP. This is an issue which has been discussed on and off for the last three years (or even longer, I can’t really keep track), with probably hundreds of threads and thousand of mail list posts (read through the php.internals mail list archive if you’re up for it). The current decision is to go with \ as the namespace separator. An acceptable decision by itself, and while I personally favored a [namespace] notation, I have no reason to believe that this is not a good solution.

There does however seem to be quite a stir on the internet in regards to decision, which I now will call the “What The Fuck Problem”. Most (if not all) public reactions on blogs, reddit, slashdot and other technology oriented sites can be summed up as “What The Fuck?”. While I’m not going to dwell into the psychological reasons for such a reaction, my guess is that it’s unusual, lacks familiarity for developers in other languages already supporting namespaces and that it might be hard to understand the reasoning behind such a decision.

The problem: to retrofit namespaces into a language which were not designed to support such a construct, without breaking backwards compability. The part about not breaking backwards compability is very important here, as it leaves out everything which could result in a breakage in existing code by simply using a new PHP version.

The discussions have been long, the attempts has been several (thanks to Greg Beaver’s repeated persistence in writing different implementations along the way) and each and every single time an issue has crept in which either breaks existing functionality or results in an ambigiuity when it comes to resolving the namespace accessed. Most issues and the explaination why they are issues, are documented at Namespace Issues in the PHP Wiki. This provides some insight into why the decision to use a separate identifier was chosen.

This seemed to get through in the flamewars discussions after a while, and people instead started to point out the “gigantic flaw”:

If you were to load a class or a namespace dynamically by referencing it in a string, you’d have to take care to escape your backslash:

spl_autoload_register(array("Foo\tBar", "loader"));

.. would mean Foo<tab>Bar. Yep. It actually would. And if that’s the _biggest_ problem with the implementation of using \ as a namespace separator, then I feared its introduction earlier for no apparent reason.

The other examples has plagued us with ambiguity issues, autoloading issues, no-apparent-way-of-putting-functions-and-constants-in-the-namespace-issues and other problems. This way we are left with the task that we, as usual, have to escape \ in a string — when we want to reference a namespace in a dynamic name — and that’s the biggest problem?

I just hope that people keep it sane and don’t implement any special behaviour in regards to how strings are parsed in regards to new, $className::. This _will_ cause problems and magic issues down the road if it ever gets into the engine.

PHP is free, it’s open and it’s yours for the taking. Fork it if you want to, or provide a patch which solves the problem in a better way. The issue has been discussed to death, and so far there is no apparent better solutions on the table. If you have one, you’ve already had three years to suggest it. You better hurry if you’re going to make people realize it now.

Additional observation: most people who has an issue with this, seems to be the same people who would rather be caught dead than writing something in PHP. Yes. Python and Java does it prettier. That’s not a solution to the problem discussed in regards to PHP.

Java printf and Booleans

The available stdout mapping in Java, System.out (PrintStream), supports printf (to format a string when outputting it) in the same manner as other languages such as C. By using System.out.printf instead of System.out.print, you can also provide a formatting string which the method can use to write the output in a custom format.

As Java supports several other native datatypes that weren’t available as regular C-types, you also have a few other options. One of these are the %b / %B identifier, which represents a boolean value.

The format string “%b” expects one argument, a boolean. This will be written as either ‘true’ or ‘false. You would (as of writing) get the same result by using the %s identifier as this would cast the boolean of a string, which in turn would give true or false, but it’s always better to be explicit about what you are doing than assuming that people understand that you understood something (which even could change..).

Upgrading to SWFUpload 2.2.0-beta

SWFUpload 2.2.0-beta has been released to fix the issue that has occured after the release of Flash 10, where regular SWFUpload-based applications ceases to work. This is because of a security update to Flash Player, where the plugin refuses to show the upload files dialog unless the plugin has focus — and the request to show the dialog is in response to an user event. This means that the user now has to click somewhere in the flash file before we’re able to show the upload dialog.

The way most file upload components solve this is by overlaying a transparent flash file over the regular user interface element, so that the user clicks the flash file instead of the visible HTML element. SWFUpload 2.2.0 supports this, in addition to creating a styled flash based button instead of the regular HTML elements.

To upgrade from our previous 2.1.0 based installation, I did the following:

Added in the settings object for SWFUpload:

        button_placeholder_id : "selectFilesButtonPlaceholder",
        button_disable : false,
    	minimum_flash_version : "9.0.28",
    	swfupload_pre_load_handler : swfUploadPreLoad,
    	swfupload_load_failed_handler : swfUploadLoadFailed

Swapped out the previous references to graceful degradation and SWFUpload 2.1.0:



Remembered to update flash_url in the settings object:

flash_url : "/flash/swfupload_f10.swf",

Added three new callbacks functions instead of using the references to the previous degradation elements (swfupload_element_id, degraded_element_id):

function swfUploadLoaded()
{
    // set the dimensions of the button to match the outer container element (jQuery!)
    swfu.setButtonDimensions($("#buttonContainer").width(), $("#buttonContainer").height());
}

function swfUploadPreLoad()
{
    // hide HTML interface, show Flash interface..
    $("#regularUploader").hide();
    $("#flashUploader").show();
}

function swfUploadLoadFailed()
{
}

Added a container element in the HTML that the Flash app will simply take control over (it will NOT lay itself transparent over this element!):

.. and remove the old reference to swfu.selectFiles();.

That should be all.