Using Coconuts - a Pythonic Blog

Username:

Password:


Don't have an account? Get one!

Python The Third... Well, almost

For a "Pythonic" blog, I haven't discussed Python much... or at all. So, I'll start with the event that's got the entire Python developer community fretting: Python 3.0!

Okay, not really. Only Python 2.6 for now. But still... Exciting, right?

Okay, so perhaps you don't know what I'm talking about here, so I'll start from the beginning. Guido van Rossum (from now on, GvR) came up with the idea of writing his own programming language that is really simple to write and read. He released his first version on Usenet (some sort of news/email-based thing that predated the Internet; I'm not sure...) in February of 1991. From what I gather of others' opinion of it, it wasn't much in the way of an actual programming language but it was a good idea and very fun to use. From there, it snowballed with new features, new libraries supported, easier ways of doing things. It all evolved into a really nice product with simple syntax stripped of unnecessary and/or ugly things. Its big debut into the world of computer science came with its 2.0 release though - in 2000 - which brought it up to par with the demands of languages. Details of why it was so are withheld for the sake of clarity. However, let me exemplify why Python became popular in the first place, by comparing it to another leading object-oriented language, Java. Here is how we would go about reading a file called "person.txt" and printing out the three things in it: a first name, a last name, and an age.

// Java
import java.io.*;
import java.util.*;

public class just_a_test
{
    Scanner sc = new Scanner(new File("person.txt"));
    String firstname = sc.next();
    String lastname = sc.next();
    int age = sc.nextInt();
    System.out.println("My name's "+firstname+" "+lastname+" and I'm "+age+" years old.");
}
# Python
print "My name's %s %s and I'm %s years old." % (open("person.txt","r").read().split(),)

# Let's do that again, in slow mode.
f = open("person.txt","r")
data = f.read()
firstname, lastname, age = data.split()
print "My name's %s %s and I'm %s years old." % (firstname,lastname,age)
http://www.opensourcenerd.com/resources/easy.png

It's beautiful! It also doesn't require to be compiled, nor does it require to be in a file that has to have the same name as its main class. And, in most cases, it's just as fast as the Java.

Unfortunately, in a frenzy to add new features and to make Python even more awesome, GvR and his developer team (a motley crew of people) made Python more and more bloated. Some code was excessively inefficient, some provided a multitude of ways to do exactly the same thing, and some started having confusing syntax - just what Python should not be. By version 2.4, this was a noted problem. Version 2.5 was to be the last "old Python" release.

With the most recent release - 2.6 - Python introduced a ton of new features and modifications to make it a transition to the future Python 3.0. This includes fixing of some known really annoying things (why does listing two types of Exceptions to catch, without a parenthesis around them fail?) and adds some really cool stuff (fractions!). Overall, for all Python programmers (and non-Python programmers, and non-programmers), I say: use Python!

I will be outlining and trying out some of the new things, so if I didn't scare you away with this monster post, I hope you come back! If I did... Come back anyway! I can be nice some times.

Note: Yes, I said I'd write about the swine flu, but honestly I have no idea how to approach such a crazy stupid panic except for this. Oh well.

New Comment
You're not logged in! Log in to be awesome!
Format: BBCode ReStructured Text

Author (max. 20 characters):