Section 1.4. Why TurboGears Values Being Pythonic

1.4. Why TurboGears Values Being "Pythonic"

When reading Python-related sites, the word Pythonic comes up fairly often. If you use Python a lot, you tend to find a commonality in how libraries approach their use. This coding style, or development philosophy, extends beyond the standard library and into many third-party libraries that you can download.

Tim Peters, one of the core Python developers, summed it up probably better than anybody. And now his words are imortalized in the Python interpreter. If you pull up a Python prompt, and type import this, you will see The Zen of Python. It's possibly the best definition of Pythonic that you'll find.

>>>import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

With TurboGears, we try to adhere to these principles as much as possible. In addition, we seek to use standard Python language constructs as much as possible. Requests coming in from the web become standard method calls when they reach your code. Expressions in the templates are standard Python expressions. Even MochiKit, which is written in JavaScript, provides a number of functions that are part of the Python standard library, but missing from JavaScript.

All of these things add up to a programming environment that seeks to ensure that you're not surprised. Or, if you are, you're pleasantly surprised that the environment did exactly what you expected it to do.

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: