[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic vs. static typing

From: "Anton van Straaten" <anton@appsolutions.com>
> Peter van Rooijen wrote:
[large snip - will comment later]
> > If the language offered me the opportunity to (formally) express
> > some of this information that I currently can't put in, I would
> > of course like the system to check whether I was inconsistent in
> > what I expressed, and tell me as soon as it could detect that
> > inconsistency ("I don't care if you call it static, dynamic or
> > whatever: I just want it checked ASAP").
> Precisely.
> > [Note: Sometimes the information I cannot express, but would like
> > to (and would like to have checked for consistency), is about the
> > types of variables or functions.
> I'm sure I'm missing something here, but that's exactly what any static
> system allows.

What you are missing is probably that I am still talking about working in
Smalltalk, where I cannot express various things that I'd like to express.

> > This is especially the case when the type is a basic one, such
> > as integer, number, or boolean. More often, the information is
> > about the type of operations (which imply their semantics). I've
> > never seen a language that allows me to specify that. Anyone?]
> I'm not sure what you're getting at.  Can you give an example?  If you
> something that acts like a basic type but has a restricted or augmented
> of operations or values, then you're talking about an abstract data type,
> which in ST languages tend to support type checking very well.  You're
> probably thinking of something else, though.

Let me explain.

I'm talking about the situation, which is very common for me, that I have
something extra I would like to say (in code), about the message I am
sending, while I might not have anything I'd like to say about the variable
I'm sending the message to.

For instance, I might want to send #size to myObject (in Smalltalk: myObject
size), and I know that I mean #size as in "the number which is the same as
the number of objects that would be enumerated if I did an enumeration". So,
the #size I am sending is #size with the semantics as defined in the
Enumerable type.

In fantasy-Smalltalk, I would perhaps write myObject Enumerable#size.
Important to note here that this is not a cast of the expression referencing
the variable; I am NOT ready to say anything about the type of the variable
myObject. It could be anything. I'll probably attach a collection to it (and
the collections I'm going to attach are certainly going to be enumerable),
but I'll decide later and I might change my mind. I might never provide a
type for myObject. But I do know that right here I want Enumerable#size.

Maybe this sounds really strange. Maybe it is :-).

In any case, I can define a precondition for Enumerable#size (size is not a
very good example here I'm afraid), and I would be able to check it right
here (if I have checking on), even before the message is sent and without
knowing which method will be bound. I also know that the postcondition of
Enumerable#size is expected to hold, so I know I expect to have a
non-negative integer if I store the result of myObject size.

I have never heard of this latter kind of typing (operation typing, message
typing, semantic typing), and don't know if there exists a name for it. If
anyone knows of any material or research about this way of annotating,
please let me know. I want to add this type of annotation to a language I'm
designing and would like to benefit from existing research if it exists.

There was also an incompleteness/partialness criticism about
variable/function typing which was somewhat implicit in this point, which is
that when I want to specify a type, it is only the type of a variable or
function in a relatively small percentage of cases, and then mostly when
they are the more mundane types. When using domain-specific objects, I'll
more often have something to say/declare/annotate about the semantics I am
expecting of the operations that get invoked (and I would like to get those
checked). And I've never seen support for that other than by being forced to
type a variable/function first.

[I'll want to say something about your type-error examples later, but wanted
to clarify this part you asked about, and where I could have been clearer,

Regards, and thanks for the stimulating comments,