Muschamp Rd

Damn PHP Coders

October 13th, 2010
PHP logo

Update: People keep finding this post in search engines, I’ve continued to work on my mashup codebase and complain about PHP, web services, and documentation. I’ve written way more PHP than I ever wanted to write…

Original Post

I haven’t made too much progress on my mashup. I’ve run into a few more inconsistencies in documentation and implementations of various APIs. So I’ve had to spend time debugging other people’s code and have discovered shortcomings in documentation and just plane errors. Arguments that are said to be optional that really are required…

With the Amazon API letting me down or at least these instructions, I couldn’t find anything better in the real Amazon API documentation so  I left a question on their forum.

With no answers forthcoming I had to look around for alternate ways to get tracks and audio previews. iTunes Music Store should have this information, but they don’t take Canadian affiliates so I wouldn’t get any money if anyone bought anything. That wasn’t even on the radar when I decided to build my CD Cover Gallery, but after putting in so much time and effort into the code and deciphering various APIs and their responses. I tried to make my code as versatile as possible and reuse-able too. Alas the more I work on it the more shortcomings and missing features I find in various PHP implementations of APIs.

I tried MusicBrainz. I’d read that it was a good source of free music information. Their API documentation isn’t the best. But as I was writing my own methods, I learned of phpBrainz. So I decided to switch my efforts to using Scott’s code but it wouldn’t even run right out of the source control system. In fact the link from MusicBrainz.org doesn’t go to the source control system that comes up number one in Google for phpBrainz…

I ended up implementing some methods for the Last.fm API that I didn’t know were missing from Matt’s PHP. I also discovered that the getInfo method in album.php doesn’t copy the track information from the XML to the array Matt insists on returning for abstraction purposes. So I think I’ll be implementing that next. However the more I work on this “small” project the more I find I need to fix and modify other people’s code so it works like it should. This means anyone looking to use my code would need all the modifications and additions I’ve made to other PHP codebases in order to get my stuff to work.

Most of the work for my albumCollection.php class is done by two methods, one in the Last.fm API to get information about an artist and another in the Amazon Product API to get information about an album. Now I can get information from MusicBrainz and I plan to get more information from Last.fm, iTunes Music Store, and possibly Amazon if someone tells me what attribute is mandatory that isn’t listed as mandatory in the documentation…

I don’t think people in PHP land test their code enough before they throw it online and tell people to download it and use it. I’m not sure a full suite of unit tests needs to be written for every class and method, but when your codebase is linked from an official website and you repeatedly say it is the best and easiest way to do something in PHP, perhaps you should make sure when you download it from the source control system, it actually will run the example code included…

How much of an obligation do people have to ensure their code works when they create a semi-official implementation of an API for a Web Service and then encourage people to use?


  • To be honest, the code I wrote is 3-4 years old and was release when I was first learning about OO programming (you can tell if you look at the quality of the code). I have flirted with the idea of taking all the code down, however I thought it would still be useful for other people to base their work off. As the licence say (you did read it right) it is provided without warranty. I make no claims that it works. It worked perfectly when it was written all those years ago, but as you’ve found out, things have changed.As it’s open source you’re free to take the code and fork it into your own project if you feel like it. I’ve kept it up purely so people can do that and so all those hours I spent using it as a learning aid are not wasted.

    Edit: Oh I forgot to mention. I was 15 or 16 when a lot of that code was written and had never been taught any programming

  • Hmm… No worries. Isn’t really you I was aiming at here. More of a general rant, however I do wonder in the era of Google and especially when an API links directly to code, is the author of that code authorized to maintain it and for how long.

    I guess it is all about pride. I did look at the licenses, this is just a hobby project, a little bolt on to my website that has grown out of proportion to the original idea.

    Cheers,

  • That’s fair enough. I think Google makes it easy to find code so that you don’t have to write it yourself, but there’s no knowing what quality the code is. It might have been fine at the time and then just fallen into disrepair

  • Pingback: Updated my PHP mashup code – Muskblog()

  • Pingback: Refactoring PHP Code – Muskblog()

  • Pingback: The Last Strange Keyword Referral Post – Muskblog()

Posts on Muskblog © Andrew "Muskie" McKay comments not necessarily so...
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.