Article View: comp.lang.misc
Article #3120CHALLENGE: typing and reusability (was: Re: blip)
From: Urs Hoelzle
Date: Fri, 22 Mar 1991 21:07
Date: Fri, 22 Mar 1991 21:07
93 lines
4280 bytes
4280 bytes
jls@rutabaga.Rational.COM (Jim Showalter) writes:
>>hoelzle@cs.stanford.edu (Urs Hoelzle) writes:
>>[A good language allows you to avoid redundancy.]
>Agreed.
>>Current type systems are too restricted to allow this, and so you end
>>up duplicating functionality in many cases.
>Disagreed. In Ada, for example, you can dynamically instantiate a
>sort generic with the type and comparison desired, giving you a type
>model that supports what you want to be able to do.
>>Thus, if you design your system correctly, ideal reusability can be
>>achieved *today* in an untyped language but not in any typed language I
>>know of.
>Ada.
I'm glad you like Ada :-) But you didn't read a crucial part of my
posting:
> know of. It can be achieved partially in languages with genericity.
> But only partially: as soon as you also use inheritance, you get lots
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> of problems with static type systems.
Note that I'm not saying Ada can't do this because it has no
inheritance; I'm saying it couldn't do it even if it had inheritance.
But you aren't convinced and I've heard this argument often enough,
so let me give an example. Please show me how you would use the many
features of Ada to write this in Ada (or any other statically-typed
language):
====================== example ==============================
Assume the following types:
type List = generic list; understands (among others)
'concatenate': returns a new [generic] list which is the
concatenation of the two argument lists"
'do': takes a procedure with one argument and applies it
to all elements of the list (i.e. a generic iterator)
type FooType = "object that understands 'foo'"
type A = some random application type, understands (among others)
'foo' and 'display'
type B = some other application type (completely unrelated to A), also
understands (among others) 'foo' and 'display'
Also assume that there exists a procedure someProc(l:List of FooType)
which iterates through the list and may send 'foo' to some of its
elements.
VAR listA: "list of objects of type A"
VAR listB: "list of objects of type B"
VAR listC: "see below"
Now, the program you're writing has to do:
listA := ... // some computation to fill the list
listB := ... // some computation to fill the list
listC := listA.concatenate(listB); // make a new list containing As and Bs
someProc(listC); // do the "foo thing" to the list
listC.do(display); // display all elements of the list
====================== end of example =========================
** So, would everybody who does *NOT* believe that dynamically-typed **
** languages can achieve greater reusability than today's statically-typed **
** languages PLEASE post a solution to this (written in his/her favorite **
** programming language)??? **
To avoid misunderstandings, please note that the above example *is*
type-safe in an abstract sense: no 'message not understood' error can
occur because all elements of listC understand both 'foo' (which may
be sent by someProc) and 'display'. However, I claim that this piece
of code won't type-check in Ada, C++, Eiffel, ...
-Urs
--
------------------------------------------------------------------------------
Urs Hoelzle hoelzle@cs.stanford.EDU
Center for Integrated Systems, CIS 42, Stanford University, Stanford, CA 94305
Technical Details
Message-ID:
<1991Mar22.210725.29448@neon.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!apple!agate!stanford.edu!neon.Stanford.EDU!hoelzleReferences:
<22032@yunexus.YorkU.CA> <11820:Mar1923:59:3591@kramden.acf.nyu.edu> <19MAR91.22493670@uc780.umd.edu> <18271:Mar2013:19:1091@kramden.acf.nyu.edu> <1991Mar20.214231.3411@neon.Stanford.EDU> <jls.669591628@rutabaga>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!apple!agate!stanford.edu!neon.Stanford.EDU!hoelzle From: hoelzle@neon.Stanford.EDU (Urs Hoelzle) Newsgroups: comp.lang.misc,comp.object Subject: CHALLENGE: typing and reusability (was: Re: blip) Message-ID: <1991Mar22.210725.29448@neon.Stanford.EDU> Date: 22 Mar 91 21:07:25 GMT References: <22032@yunexus.YorkU.CA> <11820:Mar1923:59:3591@kramden.acf.nyu.edu> <19MAR91.22493670@uc780.umd.edu> <18271:Mar2013:19:1091@kramden.acf.nyu.edu> <1991Mar20.214231.3411@neon.Stanford.EDU> <jls.669591628@rutabaga> Organization: Computer Science Department, Stanford University, Ca , USA Lines: 93