Thursday, 17 May 2012

The Old Ones are the Best

It is very common for a new technology to appear in the development world. Slightly less common is the entire development community turning round and adopting it wholeheartedly. And when they do, it's often touted as the 'next new thing' to adopt.

MVC (model, view, controller), as a way of separating logically distinct areas of code within a software development project, exists within a vast number of languages and frameworks and has come from almost nothing over the past ten years. In the Microsoft world it has heralded a complete paradigm shift away from the more traditional Web Forms development model to one focussed around demarcating code across strict lines between the user interface, the data and the 'controllers' responsible for channelling information between the two.

Like most developers working with Microsoft's tools, my first awareness of MVC came when Microsoft - slightly late to the party - launched their implementation in 2009. It was only when their third version launched in 2011 that it really took flight on their platform, primarily (I believe) due to Razor, a language designed specifically for writing user interfaces.  For most developers using .net languages it brought about a massive change in thinking about how applications work; and yet, it shouldn't have done. MVC has existed for many years, even if the name is a new one to most people.

It wasn't one of the design patterns championed by the Gang of Four in their seminal 1994 book, but if I recall the structure of some code I wrote back in the 90s, I was already using a pattern not completely dissimilar to MVC: a Java applet for the user interface, a backend database for storing data (I forget which), and a set of Perl CGI scripts for passing data back and forth; at the time, there was little choice. I certainly didn't invent it, nor these techniques, so how 'new' actually is MVC?

In fact, MVC - as a defined term, not even a concept - can be traced back even further than this. The credit truly belongs to Trygve M. H. Reenskaug, who writes:
"I made the first implementation and wrote the original MVC note at Xerox PARC in 1978. The note defines four terms; Model, View, Controller and Editor . The Editor is an ephemeral component that the View creates on demand as an interface between the View and the input devices such as mouse and keyboard."

We strive to keep our technological skills as up-to-date as possible, but there are times that the old ideas are the best; our skills are in recognising the appropriate technologies for each project we work on. If that means using development technologies older than some of the developers themselves, then so be it.

Friday, 11 May 2012

Yii - changing my perceptions of PHP

For a recent project we were required to write an application in PHP that communicates with RESTful web services.  This meant that the site itself did not require a database.  I had limited experience of PHP, and did not have the best impression of it as a language.

We looked into PHP frameworks and decided to use Yii.  This is primarily due to the following reasons:

* MVC design pattern.
* Testability (both functional testing and unit testing) is considered from the start (with phpunit).
* Although Yii does ORM, and magic like "generating classes from your database tables" it does not REQUIRE using a database the way some frameworks do.
* Widely used and relatively well established.

The result is a very fast application, with thin controllers and a service layer (services as Yii ApplicationComponents).  We have very high unit test coverage in the service layer, and we have a suite of functional tests.

Using Yii has resulted in a well-structured application that benefits from the framework, rather than the framework getting in the way.  When looking up how to do things "the Yii way" I always reacted with "that makes sense".

I feel this experience says something about PHP as a language.  It is generally-considered that the language is not as elegant as others, and it is a scripting language at heart.  The syntax often feels clunky and functions are named and used inconsistently.  Yii encourages you to write PHP in a way that felt like I was writing Java or Groovy.

This is similar to my experience with javascript.  Historically used just for some UI magic, and there are a lot of gotchas to the language, yet when used correctly it can result in well-written non-trivial applications.