[OT] Type-checking (was Re: Python Strings)

Keith Ray k_j_r_a_y at ix.netcom.com
Wed Sep 6 19:04:53 EDT 2000


In article <slrn8rd4c0.2fl.quinn at cruzeiro.ugcs.caltech.edu>, 
quinn at cruzeiro.ugcs.caltech.edu (Quinn Dunkan) wrote:

>On Wed, 06 Sep 2000 08:00:40 -0700, Keith Ray <k_j_r_a_y at ix.netcom.com> 
>wrote:
>>What most people mean by "strongly-typed" or "staticly typed" is "there 
>>is compile-time checking of variable types" (and parameter-types, and 
>>function-return-types and expressions being assigned or passed into 
>>variables/parameters/etc.).
>>
>>What most people mean by "weakly-typed" or "dynamically typed" is "there 
>>is only run-time checking of variable types" (and parameter-types, and 
>>function-return-types and expressions being assigned or passed into 
>>variables/parameters/etc.).
>>
>>C is a language that is staticly typed -- but the parameter types for 
>>non-prototyped function are not checked by the compiler, making C one of 
>>the most dangerous language in which to be a sloppy programmer.
>
>Well, I've never taken a CS class, but my impression was that:

Well, I have taken CS classes and I have a 15 year history of getting 
paid to program. And I (briefly) subscribed to the ACM special interest 
group in programming languages (SIGPLAN).  Trump. :-)  I also designed 
"Keith's Programming Language", KPL, which was never implemented, but it 
was a bit of fun. {that was so long ago, it wasn't even OO.}

[...]

>So python is strongly dynamically typed.
>C is weakly statically typed.
>haskell is strongly statically typed.
>
>In fact, C is the only language I know of that is weakly typed... is this
>"correct" usage?  It makes sense to me... but I posted this because I'm 
>sure someone out there can clear this up for me.

By these definitions, some dialects of Pascal are "weakly statically 
typed" because those dialects have a type-cast syntax, and other 
dialects of Pascal are "strongly statically typed" because those other 
dialects don't have type-casts. 

So how useful is the meaning of "weak" and "strong" if the addition of 
one bit of syntax changes a language from strong to weak? Some languages 
don't require any type-casting syntax but have the same behavior by 
other forms of explicit/implicit coercian of types. 
(AppleEvents/AppleScript)

Most people are interested in whether the compiler find errors for them 
at compile-time, or if those errors need to be found via testing at 
run-time.  "static" is compile time, "dynamic" is run-time.

MOST people who innocently ask about weak/strong "types" are really 
asking about static/dynamic type-CHECKING because they don't know about 
this distinction between weak/strong/static/dynamic.

>I would consider the language's reference/binding semantics to be a 
>seperate issue from typefulness. 

Value types and variables types ARE important to those people who are 
asking about static/dynamic type-checking. Otherwise, what would be the 
point of declaring a variable "boolean" if it is okay to assign a 
"float" to it? 

In SNOBOL (if I remember correctly), everything is a string, but you can 
do math if the string contains something that can be interpreted as a 
number. This is definately NOT static type checking. However, the "type" 
of everything is _always_ "string". Since the type is always a string, 
that makes is a "strongly-typed" language, doesn'it?  

Perl is the same way, right? If I assign "1" to a variable in Perl, I 
can do math using it AND do a string operation using it. Assuming the 
operations are not destructive, the value of that variable is still "1" 
-- it may have been implicitly coerced to a number in one of these 
cases, but the type of the thing that the variable references is still 
is a string.

Some people feel that the static-type-checking of Ada, Java, C++, etc., 
is necessary to allow building large systems. The compile-time 
type-checking insures that "right" types are being passed into functions 
that would blow up if the wrong types were allowed to be passed in. 
Other people, who have built large systems in Smalltalk for example, 
know that large systems can be built, as long as there is enough testing 
and discipline in creating that system.

> In fact, C and perl (and java?) are the only
>languages I know of that always use explicit references/pointers.

Pascal has always had a pointer syntax, but only some dialects of Pascal 
allowed "type-casting" of pointers and values, just like C.

"References" to objects allocated in the heap are the normal usage in  
Smalltalk, Object Pascal, Objective-C, Python, Oberon?, Modula3?, some 
object-oriented dialects of Forth, and just about every other OO 
programming language that I've heard of.  C++ is, as far as I know, the 
only language that allows objects to take space on the stack instead of 
the heap.

NewtonScript (correct name? its been a long time) is a language that has 
objects, but does not have classes.  Objects have named 'slots' that can 
take any value (including references to other objects).  Local variables 
also have no declared type.  A kind of inheritance is implemented by 
automated look-up using a 'parent' slot referencing another object. 
There is no way (AFAIK) to "query" the "type" of an object in 
NewtonScript. You send an object a 'message' (or call a method) with 
some other objects as parameters, and either it runs successfully at 
run-time, or not. Does this lack of a "query" capability make 
NewtonScript "weak"?

-- 

       <http://pw2.netcom.com/~kjray/>



More information about the Python-list mailing list