What the framework is this?

February 16th, 2010 by Christopher Reding

If you’ve been coding (and not under a rock) you’ve heard the word framework tossed around quite a bit, but what is a framework and why use it.

From Wikipedia:
“A software framework, in computer programming, is an abstraction in which common code providing generic functionality can be selectively overridden or specialized by user code providing specific functionality. Frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined API, yet they contain some key distinguishing features that separate them from normal libraries.”

That explains it? If you are like me then that was more confusion than an answer. For a long time this sort of lofty explanation was a road block to truly grasping the power frameworks contain. However, step forward a few years, and poof I got it. While learning to code from scratch was probably the best thing that could have happened, learning to use a framework (on top of that knowledge) made it all the better. So what is a framework in common terms?

To be concise a framework is a set of tools prefabricated to assist you in building your application. Imagine building a house if you had to create the hammer, mold nails, build a saw, etc. At one time this was how people lived, but progress brought the toolbox. The same is true with coding. Frameworks become our toolbox, and the API gives access to our tools. This makes us more efficient and saves time so we don’t have to re-invent the wheel (or class) every time we embark on a new project. Now we know what and why frameworks, lets get to the how.

For this discussion I’m going to limit it two two examples. The first is a PHP library that goes by the name of Codeigniter. I’m not saying Codeigniter is better than other libraries, that is a personal choice, I’m just using it as an example here. Codeigniter is a MVC framework (we’ll discuss MVC later) it enables the development of robust applications in a fraction of the time it takes to code traditionally. Codeigniter consists of a series of classes, libraries, helpers etc. that together make up a pretty nice toolset for developers. For instance say you need to run a database query, in the past this would require something like this:

$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);
if (!$link)
{
die(‘Could not connect: ‘ . mysql_error());
}
$query “SELECT Foo FROM Bar WHERE Foo = 1”;
$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result){
echo $row['Foo'];
}

becomes this:

$result = $this->db->query(“SELECT Foo FROM Bar WHERE Foo = 1”);
if($result)
{
foreach($result as $value):
echo $value->Foo;
endforeach;
}

As you can see the code is a lot shorter and more streamlined. This is due to Codeigniter’s database class, one of the many tools you can use to speed up your workflow.

Another example is jQuery. jQuery is a javascript library containing predefined functions that allow you to harness the power of client side scripting without having to write
excessive amounts of code. Just as before I’m not saying jQuery is the best, there are others out there that are just as useful, I’m just using it for this example. jQuery allows us to create animations, load data, submit forms, interact with the DOM, and much more. Without jQuery (or a similar library) this would entail lines of code that may or may not work (in ie6 ;) ). The beauty of jQuery in found not only in it’s simplicity, but in the ability to function in an expected fashion across browsers. This frees up time to focus on presentation as opposed to compatibility. jQuery also offers us the ability to interact with data in real time without having to reload the page creating a more desktop-esque experience within the confines of the browser. This brings us to where.

Now that we’ve discussed the How, what, and why you may be wondering where to learn more about all these wonderful tools, and so I bring to you the resources, a series of links to sites that I think are awesome.

http://codeigniter.com – the name says it all
http://jquery.com – the home of jQuery
http://nettuts.com – great tutorials and information on EVERY web subject
http://www.prototypejs.org/ – javascript framework
http://mootools.net/ – javascript framework
http://cakephp.org/ – PHP framework
http://www.alistapart.com/ for the purist and web standards guru
http://usejquery.com/ – a great resource for tutorials using jquery

This is just a few, if you have any favorites mention them in the comments.