What is Expressiveness in a Computer Language

Pascal Costanza pc at p-cos.net
Tue Jun 20 12:01:34 CEST 2006


Marshall wrote:

> The conversation I would *really* like to have is the one where we
> discuss what all the differences are, functionally, between the two,
> and what the implications of those differences are, without trying
> to address which approach is "right" or "better", because those are
> dependent on the problem domain anyway, and because I can
> make up my own mind just fine about which one I prefer.

My current take on this is that static typing and dynamic typing are 
incompatible, at least in their "extreme" variants.

The simplest examples I have found are this:

- In a statically typed language, you can have variables that contain 
only first-class functions at runtime that are guaranteed to have a 
specific return type. Other values are rejected, and the rejection 
happens at compile time.

In dynamically typed languages, this is impossible because you can never 
be sure about the types of return values - you cannot predict the 
future. This can at best be approximated.


- In a dynamically typed language, you can run programs successfully 
that are not acceptable by static type systems. Here is an example in 
Common Lisp:

; A class "person" with no superclasses and with the only field "name":
(defclass person ()
   (name))

; A test program:
(defun test ()
   (let ((p (make-instance 'person)))
     (eval (read))
     (slot-value p 'address)))

(slot-value p 'address) is an attempt to access the field 'address in 
the object p. In many languages, the notation for this is p.address.

Although the class definition for person doesn't mention the field 
address, the call to (eval (read)) allows the user to change the 
definition of the class person and update its existing instances. 
Therefore at runtime, the call to (slot-value p 'adress) has a chance to 
succeed.

(Even without the call to (eval (read)), in Common Lisp the call to 
(slot-value p 'address) would raise an exception which gives the user a 
chance to fix things and continue from the point in the control flow 
where the exception was raised.)

I cannot imagine a static type system which has a chance to predict that 
this program can successfully run without essentially accepting all 
kinds of programs.

At least, development environments for languages like Smalltalk, Common 
Lisp, Java, etc., make use of such program updates to improve 
edit-compile-test cycles. However, it is also possible (and done in 
practice) to use such program updates to minimize downtimes when adding 
new features to deployed systems.


Pascal

-- 
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/



More information about the Python-list mailing list