Paul Graham on Python hackers

Kirk Job-Sluder kirk at eyegor.jobsluder.net
Mon Aug 9 10:20:53 EDT 2004


On 2004-08-09, beliavsky at aol.com <beliavsky at aol.com> wrote:
> Kirk Job-Sluder <kirk at eyegor.jobsluder.net> wrote in message news:<slrncha2q0.1sd3.kirk at eyegor.jobsluder.net>...
>  
>> In previous writings Graham tends to focus more on language fundamentals
>> rather than the scope of features or the process of compilation.  Python
>> is closer to Java in that they are both strongly Object Oriented languages in
>> contrast to perl's OO framework that feels more bolted on than integral
>> to me.
>
> Python, unlike Java, does not force OOP upon you -- it can be treated
> as an imperative language. I think this is a plus especially when
> first learning the language or writing small programs. A Hello World
> program is just
>
> print "Hello, World"

However, and I see this as a pretty important distinction.  Most things
in python are objects.  "Hello, World" in python is more than just a
reference to a series of bytes terminated in a null.  

>>> "hello world".capitalize()
'Hello world'
>>> "hello world".upper()
'HELLO WORLD'
>>> "hello world".find('or')
7

> class HelloWorldApp {
>     public static void main(String[] args) {
>         System.out.println("Hello World!"); //Display the string.
>     }
> }

The differences here are trivial from what I can tell.  What is
happening here are three things:
1: the creation of a class boundary around the program.
2: the creation of a main function that runs when the program starts.
3: output of a string to STDOUT.

Python does #1 and #2 implicitly unless given instructions to do
something different:
http://www.python.org/doc/current/lib/module-main.html

#3 is provided by defining print as a built-in statement that masks
writing to sys.stdout().  

The magic of python is that its Object Orientation is so
well-implemented that it takes away much of the pain and suffering
imposed by Java, and even by C++. These code snippits just show that
python is a high-level OO langugage as opposed to Java which is a lower
level (middle level) OO language.

Of course you can use OO languages to do imperative programming.  (A
fact greatly lamented by OO purists.)  You can even do imperiative
programming in java once you set up your main function.  However, I've
found that most languages are built in such a way to make one paradigm
easier than another.  The thought of OO programming in gnu lisp sends
chills down my spine.  OO programming in perl is doable but cumbersome.

But as an example of what Graham was walking about, we need only look at
the manpages for perl and python.

The perlobj manpage says:

    First you need to understand what references are in Perl. See perlref
    for that. Second, if you still find the following reference work too
    complicated, a tutorial on object-oriented programming in Perl can be
    found in perltoot and perltootc.

In contrast the python manpage simply says:
    Python is an interpreted, interactive, object-oriented programming lan-
    guage  that  combines  remarkable power with very clear syntax. 

In perl5, objects are thin wrappers around references.  Python just
says, "I'm an object oriented language" and then goes on to tell you how
to use the large numbers of available objects.  

--
KirK



More information about the Python-list mailing list