Request For Comment

When a developer on an open source project wants to recommend that a particular feature be added, often times that developer will create and RFC. RFC stands for Request for Comment, by creating an RFC, the author creates a comprehensive proposal that other developers can then consider and critique. Although this process requires some level of bureaucracy, it's probably the most democratic approach that can be taken to getting a new feature added.

I don't often read RFCs, but for software projects that I really care about - software projects that I am directly affected by - I will try to stay abreast of the thinking amongst the core developers and try to see the direction that the language is moving in. One such project is the PHP language itself which is not only used to develop a tremendous amount of open source projects, but it itself is developed as an open source project.

To the outsider or developer just getting started with PHP, it may seem as if PHP "just is" the way it is, or that there is something that will forever be constant about it. This is not really true. Although there is a huge install base for PHP and changing the language can create backwards compatibility issues, in order for the language to evolve, it must change. I've blogged about changes is PHP that I thought were important, closures, traits, and namespaces are three such additions that I am a fan of.

I Wish I Could Hear the Debate!

A few years ago, Imam Siraj Wahaj gave a talk at the New York University to a group of college students. In that talk, he briefly contrasted Usury in Islam, Christianity and Judaism. Usury, or the practice of charging excessive interest rates on loans, is a practice that has always been strictly prohibited in Islam, and was once prohibited in Christianity. Over time, leaders got together, and gradually, the Christian perspective on usury came to diverge from the total Islamic prohibition to allowing for certain instances to allowing for almost all but the most criminal forms of usury to be permissible. His point was not to take a stance per se on Usury or to suggest that Christianity is necessarily better or worse for this reformation, but his point at the time was:

Wouldn't you have loved to be there and hear this great debate? To listen to the arguments for and against and see how these religious scholars viewed the world, religion and the almighty? How might have being present at the that time and witnessing the discourse sparked your own thinking and opinion formation?

Well, when it comes to PHP, you can see a fairly comprehensive list of RFCs on the RFC Wiki and also, follow the discussion of the core developers on the mailing list (both listed below). To me, I think this is an amazing opportunity to see how a language that many of us love (or hate) came to be the language that it is today. The developers on these mailing lists may be a higher caliber developers than those that we may typically come into contact with in our work, projects and classes. Seeing how they think an interact can be like an long-distance mentorship for a learner who's willing enough to follow these discussion and work to make sense of them all. Personally, I followed the PostgreSQL mailing list for years as a silent reader, and although many times I could not quite follow the discussions, I found that it was a rich source of ideas to look into a learn about.

Resources

Some RFCs I Am Currently Following…

High Level View

Traits are the most significant new feature of the upcoming PHP 5.4 release.

From a high level, traits make it easier for programmers to re-use code. Code re-use is a major architectural goal software projects because it makes development faster and cheaper. That being said, traits don't make it possible to do anything that could not have already been done before with PHP, however, traits offers a better and perhaps more natural or expressive way to achieve certain kinds of re-use.

Expressiveness

People seem to put software development into the category of mathematics, as if writing a program was like writing an equation - it's usually not. Personally, I see programming as being a form of similar of creative writing. The essential experience of programming is thinking and writing. The main tool of a programmer is the integrated development environment [IDE] which is really just like Notepad on steroids. So, we sit at our desks (or on a train) and express our ideas through writing. When something comes along that makes the language we use to communicate our ideas more expressive, this is a big deal!

Expressiveness is probably why I am not a fan Java, and I like Javascript - once you are comfortable with Javascript, it offers many concise language constructs with which to express yourself, whereas Java's pedantic nature makes even the smallest idea tedious to type.

My intention in writing this post was not to talk about PHP, not Javascript, but I think to see the significance of this development, it's helpful to look back at PHP 5.3's most major language enhancement - closures / lambda functions / anonymous functions and to note that it was most likely the mainstreaming of the closure feature in Javascript that put a sort-of peer pressure onto PHP to have the same feature. I certainly remember using closures in Javascript for a while and wishing I could do the same in PHP. I'm not sure if another language has popularized traits (I know Scala and Objective-C have traits as well), but wherever the inspiration came from, traits are certainly a welcome addition.

The Specific Advantage

Class inheritance has been the main way of achieving code re-use in PHP up until now. At Virtue Center, we recently came across a scenario where we had two Classes (model classes) that we wanted anothter class to re-use. Prior to the addition of traits, we would have had to set up a linear inheritance chain. Something like: FrameworkModel -> EventsModel -> BlogModel -> CustomerModel. This is frustrating, because it makes it seem as if BlogModel has something to do with EventsModel (it doesn't) but there is no other way for CustomerModel to inherit the methods of both classes other than to line them into a chain of inheritance. Enter traits. Now, we can make EventsModel as trait, BlogModel as trait and then CustomerModel would extend FrameworkModel and make use of both the EventsModel and BlogModel. The two traits are no longer in any relationship other than sometimes they are both being employed by the same class.

The Subtle Advantage

Classes serve essentially two purposes: first, as a template from which to instantiate objects, and second, as a grouping of methods. Traits are simply a grouping of methods, they can not be instantiated. Having to define certain groupings of methods as a class (even if you make it abstract) is a bit misleading in a way, because is implies that maybe you might want to instantiate these groupings, although when they were not written with this intentions in mind. Now, we can use traits for this purpose as we would no longer need to make such groupings as a class.

Relevant Links

MongoDB + Solr

Users have a very high expectation for search results today. Most users perform their searches on sites like Google and Amazon, who have spent millions of dollars to create an amazingly optimal search experience. And then there is the search on your site. If you have a search on your site. The days of MySQL full-text search are over - users expect more. phrase search…. stemming… synonyms… term expansion… relevance ranking… term highlighting… etc.

Enter Solr. Solr is an amazing text search and retrieval server originally created at CNET. It's fast, full featured and free. But - and here is the catch with all such search systems - it does not operate on your database or file system directly, but rather on a separate index that must be maintained less it fall out of sync with the source data.

As many an experienced programmer can tell you, synchronization is a "hard" problem because essentially it falls under the category of maintenance. To address that, at Virtue Center using PHP we have extended the baseclass of Mongo and integrated Solr directly into Mongo. This direct integration makes having a separate "trigger" or search indexing process no longer necessary because Solr documents are indexed, updated and deleted immediately after the Mongo document is operated on.

This blog post is a work in progress. We will post some code samples soon.