ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT

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

5/18/01

Nicholas Petreley, 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.

On this topic

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.

Nick Petreley is the founding editor of VarLinux.org (www.varlinux.org). Reach him at nicholas@petreley.com.




Sponsored Links

Dashboards & KPI Reporting for Business People
PivotLink provides a new perspective on your business with drillable dashboards & reports.
CAPTURE Quad-Core Performance
Check Out The Latest In Capturing The Value Of Xeon® Quad-Core Servers For Your Business.
SOLVE SUPPORT ISSUES on the First Call!
REMOTELY CONTROL AND CONFIGURE SYSTEMS. Easily install applications, updates. All from your Desktop!
FREE Application Discovery Tool from Sophos
Scan your network for VoIP, IM, games and other potentially unwanted applications.
FREE Sophos Threat Detection Test
Scan for viruses, spyware & adware. Is your AV catching everything?
» Buy a link now

Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
 Home   Application Development  Programming tools  Programming languages  Server Scripting  Python
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Industry Standard   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.