Sponsored Link •
Bill Venners: In your keynote, your seventh reason for loving Python was, "It doesn't treat me like I'm stupid." Could you speak a bit about that?
Bruce Eckel: When Java came along, they bashed C++, a language that I had worked with I don't know how many years. I had been going to standards committee meetings, etc, and I understood C++ very well. I understood the C++ design decisions. The Java people poo poo-ed those design decisions. They said, "C++ is bad and we're really great." But then I started delving into Java, and there were a number of decisions they made that were not particularly enlightened.
For example, Java doesn't have operator overloading. In C++, operator
overloading is in fact quite complicated. But a lot of that complexity is because
you can pass objects or references in C++, and there's no garbage
collector. So operator overloading gets really messy in C++. But, ironically, in
Java, you could easily do operator overloading, because all those problems
basically go away. First of all, in Java you're only dealing with references. And
second, you've got the garbage collector.
Nevertheless, they came along and
said, "Well, we decided that operator overloading was a bad thing, and it would be
dangerous for us to let you have it. So you can't."
Well, OK, except that
Strings in Java have operator overloading. You've got operator
+ and operator
+=. It's a little difficult to swallow,
because they're saying operator overloading is bad, but gee, it was awfully useful
here. That's precisely true. Operator overloading is useful in certain areas. Java is filled with
those sorts of decisions.
In Python, they basically say, "You want it? You can have it. We're not going to try and protect you from yourself, saying these features are too dangerous." So there's all kind of stuff in Python. Python has metaclasses, for example.
Bill Venners: What are metaclasses?
Bruce Eckel: Metaclasses are really powerful. If you look at a
class as a factory for objects, a metaclass is a factory for classes. A class has
the information about what an object looks like. If you mess with a class, you
change what the objects look like. If you mess with a metaclass, you change
what the classes look like. For example, with the help of some of the
people in the Python community, I duplicated Java's synchronized keyword using
metaclasses. So I can have synchronized methods on classes. Whenever you
synchronized, the metaclass would insert the necessary code at the
beginning and the end of the method. You start looking at that and you go, wow.
Bill Venners: So metaclasses are an example of where the Python designers are giving people something that may be a little dangerous if abused, but very helpful when used appropriately.
Bruce Eckel: It is hard to say. We might see something like metaclasses eventually in Java, because they've been adding more interesting features to Java, like dynamic proxies. For Python, things like dynamic proxies and delegation are just one-liners. They are quite straightforward.
One of the things I find that's remarkable about Python is that it has a very even learning curve. Maybe it's not even a curve, It's kind of a straight line. Learning Python has a zen-like quality, because Python doesn't try to make the world something else. The designers of Java wanted to make the entire world look like a Java virtual machine and the Java libraries. In addition, Java's designers decided that the C++ approach of allowing functions and global variables in addition to classes is bad. So everything in Java has to be declared in a class. For that reason, Utah Valley State College stopped using Java as an introductory language. They actually teach C++ as a first language, because they found it a lot easier.
Python would make an even better first language to teach programming. It's such a gentle learning curve. You can start with scripts, and of course some people dismiss Python as a scripting language, because you can script with it. You start teaching scripts. You can teach functions. Then later you can add classes. Then you can go onto things like metaclasses. Python has many more of these powerful constructs that you can learn when you're ready. And I think that's very impressive, because it doesn't say you should only be an object-oriented programmer.
And in addition, the way that Python treats platforms is very reasonable. Python says, we're going to allow you use all the stuff you want in Unix or Windows. Now, beware that if you decide to use these specific, Unix-only libraries, you're not going to be cross-platform. But you'll know that. So it's your choice. Rather than saying, "No, you can't even know what the underlying platform is." So Python can be cross platform just fine. But if you want to talk to the specific operating system—if you want to talk to the Unix facilities, to COM, or whatever—it says fine. You can do that. They say, "How can we help you," rather than, "How can we coerce you behave the way that we think you should?"