Les Schaffer schaffer at
Tue Apr 10 07:22:12 MDT 2001

1.) another thought on the topic of OO and compartmentalization:

does OO really further this end over, say, procedural languages? After
all, before OO, one was supposed to design clean subroutines with
minimal global variables and a well defined calling interface.

is/was this any less effective, in practice, in structuring the work
of programmers?

2.) on C++ vs. Java: this invokes many religious wars. i know a lead
programmer at Xerox who refused to work on any more C++ projects
because of the filthiness of the language. i know computer scientists
who are developing matrix classes for numerical simulations. supposed
to be very fast for computation. They are the ugliest structures i
have ever seen written in code. worse than greek. Java seems to be
proclaimed as the new messiah, the answer to C++'s filth. But as Lou
and Jim F.  point out, the cleanliness of Java is enforced
rigidly. This is suffocating to many programmers, especially newbies
to the language.

3.)  Jim F. said:
> Also, CS curricula tend to be oriented to the teaching of computer
> science theory (primariry the theoretical aspects of data structures
> and algorithms which is not necessarily directly relevent to what
> industry is looking for in prospective programmers).

what does industry look for in prospective programmers?

4.) here is my contribution to the marxism source code repository,
hello world or its variant in two different languages. one is python,
an object oriented scripting language but where OO is left up to the
programmer. it can be easily extended in C/C++/Java/etc code. i use it
now to steer all my numerical simulations.

the other is Scheme, a functional programming language based on
Lisp. you can see (if you are a coder) how easy it is to make
object-like things with the language. inheritance and all that takes
more work, obviously. But packages already exist for Scheme and Lisp
to work the OO magic. You _could_ do this with C, but its much uglier.

Python non-OO:

print "Hello world"

Python OO:

class Salute:
   """class for saluting workers of the world.
      Documentation strings built into language."""

   # '__' means class private variable
   __saluteStr = "Hello World"

   def _init__(self):
       """Class constructor"""
       print self.__saluteStr

# create an object

Scheme non-OO:

(print "Hello World")

Scheme OO: (an example of how the structure of the language allows
---------   to create objects right in the base language)

(define (Salute)
  ;; all bindings below are local to Salute.

  ;; private instance variables
  (define numCalls 0)
  (define greeting "workers of the world unite!")
  (define apology "we apologize, signed GW Bush")
  (define signature "Les Schaffer")

  ;; private instance method (function)
  (define (increment-counter) (set! numCalls (+ 1 numCalls)))

  ;; public instance methods
  (define (announce)   (print greeting)  )
  (define (declare)    (print apology)   )
  (define (showCalls)  (print numCalls)  )
  (define (sign-declaration)
                       (print signature) )

  ;; function lookup table (makes some methods public).
  ;; wouldn't need this with one of the object packages
  (define (dispatch action)
          ( (eq? action 'announce ) announce        )
          ( (eq? action 'declare  ) declare         )
          ( (eq? action 'showCalls) showCalls       )
          ( (eq? action 'sign     ) sign-declaration)
  (print "initializing instance.")
  ;; this returns the function table from the "constructor":

;; create an instance
(define thisSalute (Salute))
(define thatSalute (Salute))

;; use the instance methods
( (thisSalute 'announce) )
( (thisSalute 'declare) )
( (thisSalute 'showCalls) )

( (thatSalute 'announce))
( (thatSalute 'showCalls))
( (thatSalute 'sign))

;; results of execution:

"initializing instance."
"workers of the world unite!"
"we apologize, signed GW Bush"

"initializing instance."
"workers of the world unite!"
Les Schaffer

More information about the Marxism mailing list