Connect Blog

Welcome to the Connect Blog where you can learn about the wonderful world of Connect and all that happens here.

RSS Logo RSS 2.0

June 2010 Posts

6/1/2010 1:55:59 PM

Improving productivity and maintainability with MVC

It's impossible to work within a software development team these days without having enthusiastic discussions about something called 'MVC'. In broad terms, MVC (Model View Controller) is an 'architecture pattern', which Wikipedia defines as:

"Software patterns that offer well-established solutions to architectural problems in software engineering."

In software engineering, as with any other construction business, I can't stress the importance of applying good architecture and design patterns enough. MVC is one such pattern which has been around for a long time - its origins can be traced back to 1979 and the Smalltalk programming language, yet has recently seen a huge surge in popularity as it has proven to be a natural fit for web-based solutions. I'll try not to bore you with a lengthy discussion of MVC concepts, but a short overview is necessary before I discuss the benefits that the MVC pattern can bring to projects.

What is MVC?

In short, MVC projects consist of at least 3 distinct areas of responsibility:

  • Models - Concerned with data modelling and capturing the project's business requirements.
  • Views - Presentation / user-interface components. A view generally provides a visual representation of data in the model(s). On a web site, these are usually web pages or HTML snippets.
  • Controllers - The engine room. Controllers facilitate the flow of data through the application. A controller will generally respond to some form of user-input, and then pass data to or from the model before handing another view back to the user.

So what does this actually mean? At its simplest level, MVC encourages developers to break their projects down into manageable, independent components with clearly defined lines of responsibility.

Back in the old days of writing Classic ASP or PHP spaghetti code, now often referred to as an anti-pattern (opens new window), it wasn't an uncommon sight for web pages to comprise of a mix of HTML mark-up, database access code and business logic all in one place, which while quick to write would become increasingly difficult to test and maintain during the course of the project's lifespan.

Instead, using the MVC pattern we are encouraged to break apart the tightly coupled dependencies that can exist in typical implementations (e.g. the user interface should not need to know how to access the database), which leads to code that is more modular, easier to maintain, and much more robust.

What are the benefits of MVC?

There are many benefits to using the MVC approach, some of the more tangible ones are:

  • MVC's architecture makes it much easier for different team members to work independently on separate aspects of the system. For example, designers can work on the views without needing to understand how the underlying database technology works. Likewise, the programmer with no interest in user-interface design can focus solely on modelling the database and business requirements of the project.
  • MVC projects are very easy to test. Developers typically create 'unit tests' which can be run automatically and allows them to quickly verify that each part of their application behaves as expected. Being able to break an application down into the loosely coupled components that MVC encourages is key to being able to create good unit tests.
  • MVC projects tend to be modular by nature, which makes it much easier to alter (or even rewrite) one part of the application without it adversely impacting on other areas. MVC makes it very easy to achieve Separation of Concerns (opens new window) - a key principal to writing code that is easy to maintain and refactor.

Where do we use MVC?

We work with plenty of legacy applications written using non-MVC frameworks, such as standard PHP, ASP, and ASP.NET Webforms sites. These all fulfil their purpose and certainly haven't become bad applications overnight! Likewise, we won't be abandoning popular products such as Wordpress any time soon just because they aren't MVC based. However we have been shifting greenfield project development to MVC frameworks. Some of the MVC based solutions that we currently use are ASP.NET MVC, CodeIgniter - a PHP-based MVC framework, Joomla – an MVC-based CMS and Umbraco CMS - moving to ASP.NET MVC for its next release.

Of course, there is no such thing as a silver bullet in the software development world and MVC is no exception. It's possible for a good software developer to craft elegant solutions no matter what architectural pattern or framework is used, just as no amount of 'best practices' is going to save a poor developer from creating buggy, unmanageable code. But by encouraging you to adopt proven design patterns there’s no doubt that MVC empowers and encourages developers to create code that is elegant, reusable and robust - and that can only mean happier clients.

6/10/2010 8:57:57 AM

Twitter User Density

It is fair to say that social media is rapidly becoming a necessary tool in any organisation's marketing toolkit. However, for any business to justify its time spent on social networking, it really needs to understand the true opportunity that particular social media audiences represent. For example, if you are a business local to Brighton, it would really help if you knew how many Twitter or Facebook users were in your geographic locale so you could make a more informed choice of social media service to promote yourself in.

We thought this was worth investigating, so armed with Microsoft Excel and data sets available online we came up with a league table of towns in the UK with highest densities of Twitter users. Interestingly, although London had the highest number of Tweeple, it was actually 10th in the list when population density was factored in, out-performed by many of the UK's media cities including Manchester, Liverpool, Glasgow and Bristol. We have summarised the full results in the figure below (click upon the image for a full-size version):

Link for image showing density of Twitter users in UK towns opens in new window

Circles represent number of people signed up to Twitter with a particular location set per head of population.  Twitter user numbers from Twellowhood (opens new window) with some amalgamation of numbers where multiple spellings of the same place name had significant numbers of users.  Population figures from Wikipedia (opens new window).

6/25/2010 3:26:08 PM

Google Analytics Application Gallery

The Google Analytics Application Gallery has been available for a little while now. Working for a provider of content management solutions, I noticed with particular interest that there are now Google Analytics plug-ins for both the Umbraco and WordPress Content Management Systems.

The Umbraco CMS plug-in (opens new window) makes it easy for editors or administrators to not only get an overview of visitors, bounce rate and other standard reports, but create their own custom Google Analytics reports. This could be a great way of reporting on standard key performance indicators to authors or technical reporting to a webmaster, without swamping them with unnecessary data such as highly customised campaign tracking.

The WordPress plug-ins not only support website owners, but also allow Google Analytics data to be displayed in your posts.

New applications that may improve your efficiency and help you get more out of Google Analytics are being added all the time, so it is well worth a visit.