Section 1.1. Why TurboGears?

1.1. Why TurboGears?

The good news is that many, perhaps most, of your problems don't stem from what Fred Brooks (in his famous essay No Silver Bullet) called the "essential complexity" of the task. Instead, many of your problems are imposed on you by your programming language, your database tools, the nature of web development, and the framework/tools you are currently using.

That might not seem like that's good news to you. But it is! Nobody can solve the essential problems of your application for you. Those problems are unique to the application you want to write, and there's no way around solving them yourself. Fortunately, lots of people are working on TurboGears to move all the accidental complexity of your application into the TurboGears framework so that you don't have to write that code any more. They do this because all of that accidental complexity applies to their projects, too.

Because you'll write less code using TurboGears, learning the ins and outs of TurboGears programming has the potential to make you significantly more productive and can give you the tools and free time you need to make your applications sexier and more responsive.

In other words, better tools such as TurboGears can solve a lot of your problems and make programming complex web applications a lot easier.

1.1.1. Making Easy Things Easy

TurboGears brings together a number of the best tools available in Python for writing maintainable, database-driven, Ajax-enabled web applications.

Every web application is composed mostly of code that does the following:

  • Gathers user requests and processes them appropriately (flow-control)

  • Organizes and stores all kinds of data in a database (object relational mapping)

  • Generates pages (hopefully nice looking pages) to present back to the user (presentation)

TurboGears brings together best-of-breed tools that make these three things "dropdead easy."

CherryPy enables you to create new URLs simply by creating a class or function with the right name in the root controller class.

SQLObject enables you to define a class for a particular set of data and have it map automatically to a relational database. In fact, as soon as you've defined your data classes, you can generate the database itself with the simple command: tg-admin sql create.

Kid, a templating engine, enables you to create templates that can be viewed in a browser without any preprocessing, which can be handed off to a designer, who can tweak the look in her favorite WYSIWYG editor.

1.1.2. Making It Easy to Maintain

If you look at a typical PHP, ColdFusion, ASP, or JSP application, you'll see that nearly every page includes sections devoted to user presentations, database access, and flow control, and that all of this code is jumbled up together in one tangled mess.

For small applications, this works fine; but when things start to grow a bit, it gets pretty hard to maintain. When your boss asks you to make a simple change in one place, you can easily break things in code in another file; and if you aren't careful, you might not discover the breakage until a week later when one of the VPs calls to tell you about how he made a fool of himself when he did a demo of your application for a client and everything fell apart.

Eventually, you start cringing inside every time a user comes to you with a change requestand that's no way to live! You start coming up with excuses, customer requests get ignored, and your application starts to suffer from neglect. Finally, your users move on to something that works better, and your application dies an unnecessary death.

TurboGears helps you to solve the maintainability problem in a couple of ways:

  • It pushes (but does not force) you to structure your code to maintain what "enterprise software architects," whoever they are, call the model-view-controller (MVC) paradigm.

  • TurboGears has compartments for presentation code (templates or views), flow-control code (controllers), and data-persistence code (models).

We talk more about MVC in Chapter 3, "The Architecture of a TurboGears Application," but for now you can think of TurboGears as one of those metal dinner plates you always see in war movies. You know the ones with separate compartments for potatoes, vegetables, and your main dish.

Beyond the basic MVC program, TurboGears is written in Python, which is designed with as much emphasis on readability as ease of programming. This means that when you come back to old code after a couple of weeks or months, Python is designed to help you understand what is going on as quickly as possible, and TurboGears is similarly designed to make your code as easy to reread as possible.

Rapid Web Applications with TurboGears(c) Using Python to Create Ajax-Powered Sites
Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites
ISBN: 0132433885
EAN: 2147483647
Year: 2006
Pages: 202

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: