topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Python: The one-size-fits-all programming language

Be the first to comment | 1I like it!
May 18, 2001, 09:42 AM —  LinuxWorld.com — 

I'm a big fan of Python -- the open source programming language. In case you're wondering, Python is indeed named after the BBC comedy group Monty Python. The language was created around 1990 by Guido van Rossum, a fan of Monty Python. Since then it has matured at a phenomenal rate, thanks to its open source nature.

In its current state, Python miraculously manages to combine simplicity with incredible depth and breadth. On the one hand, Python is very similar to Java in terms of how one might apply it to build solutions and the kind of features it supports. Like Java, it is object-oriented, runs bytecode, and works well for server-side Web applications. Like Java, you can use Python to build client-side applets. There is a Netscape plug-in for this, but nobody seems to use it and it's not supported anymore. Why? Because you can write applets in Python and compile them into Java bytecode for use with any Java 1.1-enabled browser. These are but a few examples of Python's depth.

Unlike Java, Python is ideal for tossing together a quick script to do mundane work. If you're a casual Linux user, you have probably been executing many Python scripts and applets without knowing it. People use Python this way because Python is even easier to use in doing mundane tasks than Unix shell script languages, and it is infinitely more powerful. That demonstrates its breadth.

I don't mean to rekindle the Python versus Java wars that raged a few years back. Each language has its place. Neither is perfect for every need, although Python is closer than Java to being a one-size-fits-all language. But I happen to be as big a fan of Java as I am of Python. And I am drawing the comparison because you would do well to consider both if you're about to embark on a new Web application project. You just might find that Python is more appropriate than Java for your particular task.

One of the first things you'll notice about Python is its unique way of grouping statements. Python uses indentation to parse its code. Most C programmers tend to use indentation in order to make their code readable. You type an "if" statement, go to the next line, indent farther to the right than the "if" statement, and then type the code that is executed if the condition is true.

The difference is that in C you don't have to indent anything. You simply do so because that makes it easier to understand the programming logic when you come back to the code later. In contrast, you need to indent Python statements properly, or your program won't run. You can use tabs or spaces, or even mix the two, but you have to be consistent.

Indenting might feel rather odd when you first start programming in Python, however it takes just a few minutes to realize that it is not only an intuitive way to program, but it also pushes you to create code that is more readable, and therefore easier to maintain.

The other thing you'll notice is that it is as easy to create Python classes (objects) as it is to toss together a procedural script. So much so that you often end up using objects in Python even when you don't have to. That makes your code more reusable, which is always a good thing.

I've barely scratched the surface of what Python is and what it can do. If I've piqued your interest, visit www.python.org for more information. Once you have learned your way around Python and want to make your programming useful, I recommend that you pick up the O'Reilly book Programming Python by Mark Lutz, now in its second edition.

Next week I'll discuss some of the options available for server-side Web applications programming with Python.

» posted by ITworld staff

LinuxWorld.com

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources