🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #3208

Re: CHALLENGE: typing and reusability (was: Re: blip)

#3208
From: Guido van Rossum
Date: Tue, 26 Mar 1991 19:15
53 lines
2778 bytes
I tried to keep quiet in this whole (interesting!) debate, but when I
saw a program of over 200 lines of C++, just to demonstrate that you
can do heterogeneous lists in C++ (and the example needed multiple
inheritance!), I couldn't resist showing how you do this in Python,
the dynamically typed language that I have designed (posted to
alt.sources recently).  Python currently has *no* compile-time type
checking at all, which is bothersome when you are writing large
programs, but quite nice for short ones.  Surprise: Python is intended
for short to medium sized programs, either throw-away code or
prototypes, where development speed is more important than running
speed.  It does have a powerful library (including a portable window
system interface) but I believe its library is smaller than C's.

I believe that this toy program's conciseness in Python says something
about Python.  Whether it's dynamic types or something else, I'm not
sure.  (Historic note: dynamic typing in Python was probably caused
more by the desire to get completely rid of variable declarations, for
briefness, than by anything else; I figured I knew how to do run-time
type checking, but didn't feel like implementing compile-time
polymorphism.  By now, many features of Python are influenced by the
presence of dynamic typing, so you couldn't take it away without
severely damaging the language design.)

# Python supports heterogeneous lists:

class A():
	def init(self, ival):
		self.ival = ival
		return self
	def foo(self):
		self.ival = self.ival * 2
	def display(self):
		print 'This is an A, its value is', self.ival

class B():
	def init(self, sval):
		self.sval = sval
		return self
	def foo(self):
		self.sval = self.sval + 'x'
	def display(self):
		print 'This is a B, its value is', self.sval

# Create some lists of A's and B's, and a heterogeneous list
Alist = [A().init(10), A().init(20)]
Blist = [B().init('help'), B().init(''), B().init('x'*20)]
Clist = Alist + Blist

for item in Clist: item.foo()
for item in Clist: item.display()

# --Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
# Go ahead, flame me!
Technical Details
Message-ID: <3226@charon.cwi.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!uunet!mcsun!hp4nl!charon!guido
References: <1991Mar20.214231.3411@neon.Stanford.EDU> <jls.669591628@rutabaga> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar26.005805.1914@kodak.kodak.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jarthur!uunet!mcsun!hp4nl!charon!guido
From: guido@cwi.nl (Guido van Rossum)
Newsgroups: comp.lang.misc,comp.object
Subject: Re: CHALLENGE: typing and reusability (was: Re: blip)
Summary: warning: Python plug ahead!
Message-ID: <3226@charon.cwi.nl>
Date: 26 Mar 91 19:15:27 GMT
References: <1991Mar20.214231.3411@neon.Stanford.EDU> <jls.669591628@rutabaga> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar26.005805.1914@kodak.kodak.com>
Sender: news@cwi.nl
Followup-To: comp.lang.misc
Lines: 53