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

By Nicholas Petreley, LinuxWorld.com |  Development Add a new comment

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.

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    DevelopmentWhite Papers & Webcasts

    White Paper

    HP NonStop SQL Fundamentals whitepaper

    This whitepaper offers a detailed look into the fundamentals of HP NonStop SQL solutions. See how this system delivers unprecedented levels of application availability with fail-safe data integrity and meets the needs of enterprises with large-scale business critical applications.

    White Paper

    Nebraska Medical Center case study

    See how the Nebraska Medical Center implemented a SQL solution to make information more readily available to streamline operations, improve patient care and facilitate medical research with an enterprise solution running on HP NonStop servers.

    White Paper

    Concepts of NonStop SQL/MX

    For DBAs and developers who are familiar with Oracle solutions and want to learn about NonStop SQL/MX, this whitepaper provides an overview of the similarities and differences between the two products-with a specific focus on implementation.

    White Paper

    6 Things Your CIO Needs to Know About Requirements

    If your organization is not predictably successful on technology projects, there is likely an issue in requirements. CIOs must take action and own requirements maturity improvement. There are 6 main things a CIO must know about requirements.

    Webcast On Demand

    User Experience Monitoring

    In this webinar, you will learn hints & tips for improving end-user response times from Forrester Research analyst, Jean-Pierre Garbani.

    Sponsor: Nimsoft

    See more White Papers | Webcasts

    Ask a question

    Ask a Question