What a winner

May 20, 2010 § Leave a comment

Dave Reichert: what a winner. The eastern suburbs of Seattle, full of highly-paid high-tech employees, could have elected one of their own. Instead, lured by the promise of lower taxes, they voted for a Bush stooge who paid just enough lip service to environmental causes to edge out Darcy Burner in the election.

Yvonne Loriod

May 19, 2010 § Leave a comment

The New York Times is reporting the Yvonne Loriod has passed away. Although perhaps best remembered as the wife of Olivier Messiaen, she was a tremendous artist in her own right. At the Paris Conservatoire, where she met Messiaen, she taught one of my favorite pianists, the incomparable Pierre-Laurent Aimard.

Loriod played the piano for the American premiere of Messiaen’s epic Turangal├«la-Symphonie with Leonard Bernstein conducting the Boston Symphony Orchestra, along with Ginette Martenot playing ondes Martenot. She also premiered Pierre Boulez’s Structures, Book 2 along with Boulez himself in 1961.

Pretty Horrible Programming

May 18, 2010 § Leave a comment

I’ve recently inherited a smallish web application implemented in PHP (and a little JavaScript here and there), backed by a MySQL instance. The web tells me this stack is called “MAMP” because it’s hosted on a Mac OS X Server. Previously, I’ve written or maintained only a handful of web apps, all based at least in part on Java and hosted on a Tomcat or Jetty server.

Since beginning my MLIS, I’ve heard so much about how the savvy librarians wield PHP. I put aside my skepticism and figured I’d see how PHP has evolved since the last time I’d looked at it about ten years ago. This would be a great opportunity to pick up a real web language and build a website that looked cool and helped people.

Since diving in, I’ve discovered that PHP has grown but not evolved significantly from its humble origins as a little macro language for building websites. The existing code for this application is messy and scattered (the app never progressed beyond a basic prototype), but it’s basically sound. The fault here seems to lie purely in the lack of core language features that characterize mature programming languages.

PHP’s OO functionality provides programmers with classes and interfaces (a good start), but in a language that’s so weakly typed it’s hard to see what benefits interfaces provide. PHP has class constants and private (and protected) fields, but it’s not possible to declare a field both constant and private. That means that you can make assertions about either the scope or the (im)mutability of a field, but not both. For now, I’ve chosen the abstraction leak over having mutable state, but in a larger application I’m not certain how I would be sure that nobody establishes a dependency on a class constant that isn’t intended for public consumption (ie, is subject to change in future versions).

Although PHP allows programmers to declare classes and interfaces, it does not support packages or modules. Instead, programmers must use a system of includes that’s even more primitive than that provided by the standard C preprocessor. Not knowing this, I moved a bunch of SQL statements used to populate data in a page from the script that generated the page (view.php) to a data access object, declared in a file called ViewDao.php.

One of the methods in ViewDao.php returns a simple data container object (think ORM, a representation of a row in a database table as a simple object). We’ll call the container class Individual and declare in an a file called Individual.php. Wanting to separate the viewable pages from the OO backend, I created a directory called ‘classes’ and moved both ViewDao.php and Individual.php into the classes directory. In the filesystem, the directory (classes) and the script (view.php) are siblings. I added the line

include("classes/ViewDao.php");

at the top of view.php and in ViewDao.php, I added the line

include("Individual.php");

Switching over to my browser, I discovered that this approach is a great big ball of fail. The error messages were indecipherable and the failure modes unacceptable, but that’s another story. After putting in some debugging prints, I discovered that view.php was including ViewDao.php correctly, but then when processing the contents of ViewDao.php it could not find Individual.php, since it handled the include from the context of view.php rather than ViewDao.php. However, it would be incorrect to include Individual.php as

include("classes/Individual.php")

since the relative path from a script to the file Individual.php is not constant!

It turns out that the PHP solution to this problem is for every script to register a function that finds and includes the code for any class that’s used, based on the name of the class. If your web app is large enough to include multiple directories containing classes, your class loader needs to be sufficiently intelligent to find and include the right file (again, given only the name of the class). And, this function needs to be registered in every script that loads classes, thereby increasing the amount of idiotic boilerplate making up each PHP file. How to do this? Not surprisingly, it involves includes!

PHP also suffers from having a weak toolchain. I haven’t explored the debugger yet, but my colleague assures me that it’s very slow. Presumably because the language has weak typing and a backwards system of includes, the IDE support for PHP is far weaker than for Java. Neither Eclipse nor NetBeans support automatic code refactoring, finding uses of variables or classes, or code generation (I hate writing my own getters and setters). Given such an inadequate toolchain, it’s not surprising that so much PHP code exemplifies bad coding habits. The language does not encourage developers to write modular, reusable code.

I’ve gotten this far without mentioning another peeve: PHP has evidently only recently come around to supporting prepared statements, meaning that countless PHP scripts construct database queries on the fly using concatenation. Unfortunately, the number of PHP scripts that correctly escape user input is fewer (remember Bobby Tables?).

Since I’ve got a basically working prototype, I don’t think I can justify rewriting the entire application in Java, but I think this will be my last foray into PHP if I can help it. Instead, I’ll simply marvel at the websites (Wikipedia) and the frameworks (Drupal) that use PHP extensively and successfully.

Halliburton

May 11, 2010 § Leave a comment

Perhaps this is old news, but is anyone surprised that Halliburton was one of the companies involved in the oil rig whose explosion led to the spill that is currently threatening the Gulf of Mexico? Executives at BP, Halliburton, Transocean are now debating who’s actions were primarily responsible for the accident and resulting spill. Perhaps, if they can’t agree now, oil companies should be required to agree before drilling who will take responsibility for any resulting accidents, damages, or loss of life. If no company is willing to accept responsibility, perhaps they should not drill at all.

Hilbert Hotel

May 11, 2010 § Leave a comment

The New York Times posted a great article discussing David Hilbert and Georg Cantor’s work describing the size of infinite sets. I had just been reading about the Cantor Diagonalization in my copy of Michael Sipser’s Introduction to the Theory of Computation. Their illustration of the diagonalization proof is both funny and informative.

This morning, I ran across a really nice post in Jeremy Handcock’s blog discussing some inexpensive data mining techniques. These look like great tools for large datasets and I’ll be looking for opportunities to put them to use.

Los Suns

May 5, 2010 § Leave a comment

Tonight, the Phoenix Suns will play the San Antonio Spurs wearing jerseys that read “Los Suns” to protest Arizona’s recently passed immigration bill. Language Log explains that the names of teams aren’t usually translated, hence “Los Suns” rather than “Los Soles”.

Placeholder

April 28, 2010 § Leave a comment

This week, I’m working to complete final projects from my first semester of school as well as preparing for a concert with the Longwood Symphony Orchestra, and I haven’t had much time to think about the blog. So, today I’ll just put up a few links:

Lorcan Dempsey at OCLC has a nice blog post about Netflix and their transition to Amazon Web Services. In particular, I liked his discussion about sourcing and scaling, which I have not heard discussed enough since beginning my MLIS.

The Puget Sound Symphony Orchestra plays its spring concert at Town Hall in Seattle on May 8th. PSSO is not only the most fun orchestra that I’ve had the opportunity to perform with, but their ticket prices are a steal.

Finally, a plug for the upcoming concert with the Longwood Symphony Orchestra, May 1st at Jordan Hall in Boston. Other than the one concert I subbed with the West Virginia Symphony (backing Kathy Mattea, a country singer), Longwood is easily the best orchestra I’ve had the privilege to share a stage with. Given a little rehearsal time, they might even edge out the West Virginia Symphony. Saturday’s concert includes Rachmaninov’s 3rd piano concerto featuring an excellent soloist, Philip Edward Fisher, and Carl Nielsen’s Symphony no. 4, “The Inextinguishable”.

Here’s Gustavo Dudamel discussing “The Inextinguishable”.