Nov 07 2008

Web Development Essentials – Frameworks

When I talked about Web Development last week, I kicked off with a quick overview of the languages and back-end server architectures you can use to develop your site. While you can develop a site perfectly well using this simple model, when your idea gets more complex you can run into problems, face longer development schedules and end up spending more to get the site fully up and running.

Luckily, there is another aspect to be considered: web application frameworks. They have been around for a while now, but it is only recently that they have really taken off and risen to the forefront of web development. Now, you can barely move for the deluge of frameworks available for every language and platform – which is great for us developers!

What Are They?

If you don’t know what a framework is, then it is a simple concept – they are best described as being like the foundations of a building but translated to the web. They take many forms, but they generally follow one golden rule: to enable you to get your project up and running quickly, easily and with a minimum of fuss.

How they do this is usually through providing you with a library of functions and code which do the common tasks you experience whenever you develop a website, like user authentication systems, database access and visual output production. The whole idea is that you don’t waste your time re-implementing the same features you use on every site you make or that have been done a million times before but only spend your time on what is unique to your project. After all, you don’t see BMW re-inventing the wheel with every new model they release, do you!

First off, there are two concepts which are so incredibly important that I don’t know why so few developers seem to follow them. The first is KISS – Keep It Simple, Stupid. This basically means always resort to the simplest implementation, model or idea. Making things more complicated than they need to be because it is ‘cooler’ or just because you can is a bad idea. All it does is create headaches when things go wrong and ends up stretching your development schedule.

The second is DRY – Don’t Repeat Yourself. This falls back into the code re-use angle for using frameworks. If there is already a session handling routine in existence which fulfills what you need from it, why create it again? The same goes for your database access code, templating systems, everything. If you’ve done it once, you shouldn’t need to do it again.

Model-View-Controller (MVC)

The MVC design pattern (or architecture) is something which has been around in the software engineering world for a good while and is now spreading into the web development world very quickly. The basic idea behind it is that you separate your system into 3 logical components:

The MVC pattern.

The MVC pattern.

  • Model – this is the data or information which is to be present in the system, along with any business logic or rules which are to be applied to it. Commonly this takes the form of a database on the web, along with any rules which govern how it is to be treated (i.e. relationships or criteria which must be upheld).
  • View – this is the visual presentation of the system. This is easy to make an analogue of with regards to web development, it is essentially the HTML page that the user will be viewing when interacting with the system.
  • Controller – this is where most of the donkey work goes on. This is the part of the system dealing with the user inputs and changes to the model most commonly.

You may already be able to see how well this translates to a web project – its easy to see why its popularity is growing. In the end, you can end up with a much more modular system which can be tested, extended and deployed with greater ease than before with the added benefit of greater code re-use (somewhat of the holy grail amongst programmers!)

Frameworks

So, lets get onto the choices you have in this ever growing sector…

PHP

As the most popular web development language in use today, it is no surprise that there is a huge selection of PHP frameworks available now. While it would be silly to present them all, I’ve picked a few of the major ones in the community currently.

  • Zend Framework – developed by the company who were behind PHP in the first place, and who contribute a large amount of work to the language, it is a framework backed by possibly the biggest name in the community. It follows the lead of Ruby on Rails and the MVC approach.
  • CakePHP – another framework with a large following, it has been shown to be slower than Zend and CodeIgniter but is still very well featured. Again, this is inspired by Ruby on Rails and MVC.
  • CodeIgniter – a framework which is designed to be lightweight, fast and generally unubtrusive to the programmer, it is gaining popularity quickly. It really is blistering performance-wise, and its philosophy of not forcing the developer to follow a set design methodology helps it.

Ruby

Ruby is quite possible the source of web frameworks and their popularity: back in 2005 when these frameworks were beginning to take off, there was one dominant player… All the others have followed suit since.

  • That player, of course, is Ruby on Rails. The basis for so many frameworks in so many other languages, it has proven itself to be a great tool for developing sites quickly and without fuss and slashing development times. The only downside to it is that performance wise, it is somewhat of a slow poke. Don’t let this deterr you though – for an average traffic site, it is still a perfect match. After all, Twitter relies on it heavily!
  • What could be the successor to Rails’ crown is Merb. This framework claims to be faster than Rails, whilst still offering the great Ruby-flavoured taste you and your family enjoy (can gems have a flavour?)

Python

While still a relatively small player in the web market, Python has its followers. Take, for example, Google, who you would be hard pressed trump in terms of sheer web presence – they are using it for their Google App Engine platform, amongst other languages. The only problem is finding a shared hosting package which enables you to use Python, but that situation is changing rapidly, and remember, greater choice is always a good thing.

  • Django is perhaps the best known and most quickly evolving framework available for Python currently. A benefit is that it is an entire development platform in one: database, server and framework all bundled into one meaning you can simply install and get developing straight away before deploying to a more traditional architecture, if you wish. Its interpretation of MVC is what they like to call Model-Template-View (MTV).
  • TurboGears is a long-established Python framework which is enjoying a growing support base.
  • web2py is similar to Django in that it contains all the tools you need for development without any 3rd party toolkits, but is known for its shallow learning curve due to its teaching usage origins.

While this is far from a complete list of all frameworks out there, it does give you a good insight into the sheer numbers of them available. PHP for instance has dozens of them to choose from, and as always with development, it is a matter of personal taste and project requirements which will often make the decision, not just the feature set on paper.

The things that all of them have in common though are profound – they enable the programmer to quickly produce a system which can meet the requirements, and allows for rapid prototyping and generally saves you time and effort. What more could a developer want?

This is a follow-on from ‘Web Development Essentials – What Platform?‘ and is part of a series of articles on Web Development as it stands today.

Links

Geoff Adams
Programmer, Research and Development

Oct 31 2008

Web Development Essentials – What Platform?

The Art of Web Development

The web has matured greatly over the past few years with ever more complex sites and networks springing up, covering everything from managing your social life to news and information services. As these sites establish themselves, so the expectation of what a user should be able to do with the web increases. One example is the new big thing of ‘cloud computing’ – where an application stored on a single computer is a thing of the past and you access your most used programs through a web browser, wherever you are.

This is brilliant for users of course, bringing the internet into your everyday routine and enabling you to do more from wherever you are. For developers, however, it can be a headache. When you come up with a great new idea and want to make it reality, the choices you face at every stage can make or break your project. Choose the wrong platform, tools or frameworks and you could be left ruing the decision for months to come, or even worse, it could spell the end for all your hard work.

This is the first in a series of articles intended to help the budding developer out there (and maybe even the more experienced ones among you) in making these vital choices by outlining what there is available to you – and remember, always fit it in with your project and the people who will be working on it.

Language

As the foundation of everything to follow, the platform choice is crucial: it may be very hard to change half-way through because another platform has that cool new feature which would make your life easier.

The first decision you need to make is which language to use: PHP, Python, Ruby, C# or VB.NET. Even Perl, which as a web dev language is going out of fashion, is still used in some situations!

  • PHP is the old stalwart, sitting pretty on top of the heap with plenty of support, existing systems and libraries and a healthy community behind it. Although it can be a disorganised mess in places, there is virtually nothing it can’t do out of the box, and when hooked up with a good framework (such as Zend, CodeIgniter or CakePHP), the sky is the limit. It can also be blisteringly fast when done right, presenting a great level of scalability.
  • Ruby is the young upstart in the web world, thanks to its major framework Rails, and many people are turning to it as it’s the current language in vogue. Other frameworks do exist, such as Merb, but it does suffer performance-wise when compared to other options.
  • Python is another language produced from the same mindset as Ruby (Don’t Repeat Yourself, or ‘DRY’), and enjoying somewhat of a boost at the moment with its own frameworks such as Django reaching maturity on a greater scale than before (more on those later). Performance is somewhere between Ruby and PHP.
  • C# and VB.NET are of course backed by the almighty Microsoft and their .NET framework, with C# in particular is gaining popularity as the rapid development language of choice for desktop applications. Performance can be very good with these two options.

Those short descriptions do not do any of those languages justice, however. Developers often have their favourites and look down on other languages with disdain, wondering how others who use them ever get any actual work done. In the end it is really down to personal preference: any language when used correctly can be immensely powerful in capable hands whilst producing the same end product. Its how you go about it that counts, after all! In the end, only experimentation with each language will give you the true insight as to what suits your needs the best.

System: Server and OS

So, lets say you’ve chosen your language. That’s all well and good, but how are you going to let people actually view all your hard work at the end of the day? Well, you wouldn’t have thought so, but there is another big choice to make: which web server are you planning on using? It may seem insignificant, but when you’re serving upwards of thousands of pages a day, it may not seem that way any more.

Currently the ‘big three’ as they stand are:

  • Classic and open source Apache Server which runs on any system you care to mention. It benefits from a long history of development, great extensions for integration with your chosen language and endless configuration options. It may get sluggish when you start pulling in those valuable visitors on a massive scale, so it is not perfect for everyone.
  • IIS from corporate heavyweight Microsoft – only available on Windows OSes but links very tightly with ASP.NET. Servers running this will typically cost more purely due to the need of obtaining a license for the Windows Server operating system.
  • Finally, relative newcomer lighttpd which addresses the performance side of things whilst still providing the ability to run an elaborate system coded in the language of your choice along with great flexibility in configuration. Unfortunately, few commercial web hosting companies offer this as standard on their shared or managed hosting plans as of yet.

Of course, if you have the access to (and expertise using) the server you will be hosting your finished site on, you may well get to choose exactly which software you want to use.

Conclusion

When you start your project, it is important to check out what you need from the project both now and in the future, both from the actual features offered to the ease of future maintenance, upgradability and management. However, no-one can tell you what to use. You may decide to go ahead with Ruby on Rails running on a Windows Apache installation, or a Python-based solution running on an OS X machine with lighttpd – it really is down to you. Just because something is new or old does not make it a good or bad choice, nor does the fact that you might have to learn something.

After all, web development is ever evolving, and its all about keeping on top of the game, right!

Remember to come back for the next in this series of articles, where frameworks – one of the biggest buzzwords in web dev today – will be discussed in detail!

Links

Geoff Adams
Programmer, Research and Development