How do you define "object-oriented"?

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Apr 29 02:18:48 UTC 2002


Kevin Fisher <kgf at golden.net> wrote:
	I have a bit of a question...I'm just sitting down to learn Python right
	now and I'm finding it a bit too C/C++ like for my liking.

This would astonish the average C/C++ programmer.

People with that background tend to really _hate_ indentation-based syntax.
The words 'int' and 'char' go back to Algol 68, which looked nothing like C.
(I say this as a former Algol 68 enthusiast.)  No, make that 'looks'; there
are still a couple of Algol 68 compilers around.

Python shares a useful property with Lisp and Smalltalk, which sets it
off quite sharply from the Fortran/Java world.  VALUES have types, not
VARIABLES.

	What strikes
	me about Python is it's claim of "object orientation"--and yet, it has
	atomic types like 'int' and 'char' that are not objects  (shades of
	C++ and Java).
	
Originally, Python was not an object-oriented language at all, and was
not meant to be.  Eventually, object-oriented features were added to it.
At long last, it was completely rearchitected to be more consistently OO
throughout.  This makes it a bit like Lisp, where classes were added
afterwards, and built-in primitive types _weren't_ classes before but
_now_ act for many purposes as though they were.

Squeak implements SmallIntegers differently from other objects.  Does that
mean Squeak isn't object-oriented?  If you can put an object in a list, you
can put an integer or character.  That's as true of Python as it is of
Smalltalk, and in marked contrast to Java.

	Is it safe to say that something like Python is not truly object-oriented?
	Or rather--if it's not objective right down to the smallest particle,
	can it be called object-oriented?

It is quite fair to call current versions of Python object-oriented.
It is a lot closer to the ideal than Java is.  It seems to me to be
closer to the ideal than Perl, which also gets called 'object-oriented'.

	(and then there's the other question about why all new languages go out of
	their way to be so C-like...a personal beef of mine. :)
	
I think it can be fairly said of Python that its designer went out of his
way to make it NOT like C.  For the benefit of readers who are not
familiar with python, I enclose a small program that a friend wrote.
I've stripped out the comments, which considerably outbulked the code.
	
 1. import sys, string
 2. rows = map(lambda x: map(string.strip, string.split(x, ",")),
 3.            string.split(string.strip(sys.stdin.read()), "\n"))
 4. col_widths = map(max,
 5.                  apply(map, (None,) + tuple(map(lambda r: map(len, r),
 6.                                                 rows))))
 7. for row in rows:
 8.     for item in map(None, col_widths, row):
 9.         if item[1] == '-':
10.             sys.stdout.write("-" * item[0] + "--")
11.         elif item[1] == '+' or item[1] == '|':
12.             sys.stdout.write("%s" % item[1])
13.         else:
14.             sys.stdout.write(" %*s " % item[:2])
15.     sys.stdout.write("\n")

Ad 1: 'import' is like Ada 'with/use', not like C 'include'.
Ad 2-6: 'map', 'lambda', 'apply' come from Lisp, not C, and are quite
    alien to the C way of doing things.
Ad 7: identation-based syntax is very unlike C.
Ad 7: what 'in' means is determined by the class of the following expression;
    it is much closer to Smalltalk's #do: than C's 'for'.
Ad 11: the word 'elif' goes back to Algol 68 and is not found in C.

What do we find that is C-like?
- backslash escapes in strings (idea inherited from BCPL, which used *;
  idea also found in Eiffel, which uses %; backslash *quotation* found in
  Lisp).  It's handy, and there's no real point in inventing a new notation.
- item[0], but zero-origin array indexing is found in Lisp and (as a run-
  time option) in APL.  Note that the 'slicing' notation in line 14 has
  no equivalent in C at all, it goes back to APL, PL/I, and Algol 68.
- the _ % _ formatting operator (APL also had such an infix formatting
  operator) and the format codes used in the left operand.
- The names 'stdin' and 'stdout'.  Names such as 'SYSPRINT' long predate C.
  
All things considered, Python is better considered a "squashed" Lisp with
Occam-ish syntax than having nontrivial inspiration from C.




More information about the Squeak-dev mailing list