CHAPTER 3: When To Use Python
Each programmer has his preferred language, and decisions on which to use often come subjectively based on experience and preference. In fact, this sometimes doesn’t matter, as most of the modern languages can perform the majority of the programming tasks. They also mostly include the needed libraries that might be useful for day-to-day tasks. There are other times when concerns about interoperability can dictate one language over another (as well as a platform over another), but in modern times this is commonly solved by shared SQL databases, XML interchange, and web services.
Therefore, when choosing whether to use which language for your programming needs, it is important to look at the way that the language is designed—what makes it easy to use for your purpose and what impediments it may present. If the performance and features are moot points of argument, then other more intangible items such as elegance and “feel” should be more carefully considered.
That said, Python is often praised for being one of the languages that can make programmers feel more productive. It can “glue” together different applications quickly, too, and its more minor details have attracted legions of fans—and haters—from all over. Sometimes, all the opinion around Python can distract potential users from the careful consideration of when to use it—this chapter is meant to address this.
For many developers around the world, Python has evolved into the default scripting language choice. Some consider it rare that a programmer starts in Python and then suddenly discovers that the language is inappropriate—but it can happen, even if Python is scalable both in performance and project size. The general degree of freedom that the simplicity of the language allows would also mean that sometimes programmers would have to be more disciplines in the way the code is structured.
On the Desktop
A programmer can write applications on the desktop using Python. This can be accomplished through frameworks like PyGTK or WxPython. Take note, however, that most desktop applications are still coded in compiled languages like C, C#, or C++. These languages have frameworks that commonly have more sophisticated tools for development. Thus, the resulting programs are usually easier to distribute, without requiring the user to install Python first.
Python has been blessed with good tools for graphical development, including Eclipse PyDev and Wing IDE extensions. However, in reality, most of the Python developers work in a style reminiscent of the UNIX operating systems -- through terminals and standalone text editors. On other platforms like .NET or Java, the environments like the MS Visual Studio will always have a tighter integration with the language. Whether this is a good or bad thing, however, will depend on individual experiences.
Python on the Web
Much clamor has surrounded the alleged movement of Java programmers to Ruby-on-Rails, allegedly due to them getting tired of Java’s overhead and enterprise frameworks. While this may be true, this may also be the fruit of good marketing from the Rails proponents. In fact, Python also boasts of the same benefits as it has.
There are several rapid and successful web app frameworks available for the Python language, each of them with their own slant. There are also those that even share the same components. Some of the most popular include Pylons, Django, CherryPy, TurboGears, Grok, and Zope (from which Grok is based). These can all be used for serious Python applications. For example, Zope was conceived as an open-source app server, pioneering its field and proving that Python is viable even in enterprise environments. This is despite many Python proponents claiming that the idea has recently become “unPythonic”. Another popular open-source implementation is Plone, a content management system running on Zope and implemented in organizations like Oxfam and Novell. Pylons is the stuff that runs high-traffic Reddit.com, and Django sits under the hood of Revver.com.
Deploying web applications in Python is mostly a straightforward affair, even though it is not quite as simple as PHP application deployment in Apache. Object/relational mappers like SQLAlchemy cater to database connectivity very well. However, most of the web frameworks of Python have yet to catch up to Java or .NET when it comes to enterprise-grade app servers -- the latter two offer better support for failover, high-availability clustering, and server management.
.In Enterprise Settings
Most large companies and organizations have a standard development scheme on either .NET or Java—the two platforms seen by many to be best suited for enterprise applications. There is a general belief that using these will help improve the interoperability of the deployments while also lowering the maintenance costs. While Python usually does not operate in the same level of scale or ubiquity, it stands as a very useful complement. It even stands as a solid alternative when the platforms mentioned above prove inappropriate.
The common enterprise platforms are usually—and by necessity—very large and very complex. They usually depend on more elaborate tools to allow programmers to manage the code, deployments, and subsequent builds. In many applications, this may be overkill. Ideally, programmers should be able to take any language that captures their fancy when the inspiration to code hits them. Python’s immediacy allows it to be perfect for such common automation tasks, quick prototyping, and similar purposes. There are also many developers who feel that Python can give one the leeway to move beyond mere prototypes, without having to scratch all of their previous work.
This considered, Python can prove to be useful for large and complex systems. For example, YouTube runs mainly on the Python language. It is also a preferred language at many organizations, like NASA, Google, and Industrial Light and Magic. There are specialized frameworks and Python libraries for scientific work, web services, data manipulation, XML interchange, and lots of other things.
All is not sunshine and rainbows, however—the main disadvantage of Python in such enterprise settings is that programmers are usually scarcer than in other languages like Java. While Python is very easy to pick up for a seasoned programmer, the wealth of specialized training courses, books, and even certifications available in Java are yet to be matched by the language.
On top of this, the sheer expressivity and power that is offered by Python would mean that it takes a seasoned developer to create a sterling product. By design, C# or Java are more restrictive. This forces the programmer to stick to stricter rules, commonly revolving around interface compliance and type safety. For others, this can hinder productivity. Still for some, this is ideal in reducing the mistakes and accidents of design.
Lastly, concerns regarding application integration can dictate the prevalence of a specific platform or language. In the service-oriented and heterogenous landscape today’s systems live, it is usually possible to write a Web service using Python while allowing it to plug into a service bus from Java. In the end, this can be consumed by a program in Visual Basic—and we are just scratching the surface.
Python has had a long history, as we had covered. However, compatibility has not been a real concern—at least until the branching of Python 2.x and 3.x. In fact, programs that were written for Python 1.0 can still run smoothly on at least up to Python 2.5. Python has been very committed to supporting existing users of its language, with a community large enough to withstand the pressure of diverging paths.
Use Python when...
Python should be primarily considered when the following conditions present themselves:
n When you need a proven, reliable, and general-purpose scripting language complete with an extensive standard library.
n When you need a language that can be useful across different programming-related tasks, from web apps to shell automation.
n If you are familiar with and like the syntax and philosophy of Python
n And of course, if you find the language fun aside from being productive.
On the other hand, consider the following as red flags for choosing Python—or at least as reasons to consider using a different language:
Ø When you are building a massively parallel or embedded system, which would not benefit from a scripting language (mainly due to the latter’s concerns about execution speed).
Ø When you are primarily building desktop apps, especially if it will be deployed on Windows. Usually, other platforms (specifically .NET) offer more robust tools as well as easier distribution paths for the final software.
Ø If you are working with a team of less-experienced programmers. They may be better off benefiting from the plethora of training for other languages like Java. Also, they are a lot less likely to commit mistakes when using type-checked, compile-time languages.
Ø If you have needs that may be better served by a specific language aside from Python. For example, if you know Perl and you have to do a lot of text processing, then that might be more ideal.