ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xml-dev
xml-dev
Re: [xml-dev] Strong versus (weak|runtime) typing
by Richard Tobin other posts by this author
Feb 13 2003 12:16AM messages near this date
RE: [xml-dev] Strong versus (weak|runtime) typing | Re: [xml-dev] Strong versus (weak|runtime) typing
> Static Typing - Type of variables must be declared at compile time (e.g.
> C++)
> Dynamic Typing - Type of variables determined from usage at runtime
> (e.g. JavaScript) 
> Strong Typing - Variables cannot be coerced to unrelated types. (e.g.
> Java) 
> Weak Typing -  Variables can be coerced to unrelated types. (e.g. C) 

That matches my recent experience of the terms, though I think the
emphasis on variables in that is a bit misleading.  Several different
things can have types, notably objects (which exist at runtime)
variables and expressions (which exist at compile time).

Both Python and Java have typed objects - objects have some indication
of their type attached to them - unlike (say) C where objects are just
some bits interpreted according to the expression that refers to them.

Java has typed variables, Python doesn't.  Java is a little strange in
that although objects are typed, the interpretation of an object also
depends on the expresion used to refer to it: you may see different
slots ("instance variables" in Java-speak) depending on the compile-time
type of the expression.

C is not weakly-typed in normal use.  Most casts are genuine
conversions.  If x is an int, (double)x is no different from a
function call that converts an int to a double.  The compiler inserts
casts where needed in assignments and prototyped function calls.  The
only weak-typing constructs are pointer casts, function calls with the
wrong argument types in old-fashioned C without prototypes, and maybe
one or two others.

As I think Guido pointed out, static typing only catches a fraction of
even the simple non-algorithmic errors you can have.  It doesn't help
that you type-checked an integer assignment if the LHS is in inches
and the RHS is in centimetres.  It doesn't stop you getting arguments
in the wrong order unless they happen to be of different types.
And the incredible verbosity of common constructs like iteration in
Java is largely due to static typing, and is a source of errors just
by ensuring that your method doesn't fit on the screen.

-- Richard


-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org> , an
initiative of OASIS <http://www.oasis-open.org> 

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl> 
Thread:
Dare Obasanjo
Richard Tobin
Rich Salz

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved