The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Implicit versus Explicit Dynamic Typing
by Christopher Diggins
September 18, 2005
In Python variables are never explicitly typed. I consider this a Very Bad Thing.


There is a belief floating around that implicit typing makes programming easier to do and learn. I think this is rubbish. In order to explain why the following Python code is bad to a beginner you still have to explain the concept of types:

>>> x = 12
>>> y = "13"
>>> x + y
TypeError: cannot concatenate 'str' and 'int' objects
The error message is hard for a new programmer to understand because str and int aren't tangible. My next beef is that accidental type conversions is one of the most common error I see programmers make while developing code in implicitly typed languages like VBScript and Python. It is inefficient to have to track these down by first running the program, and having to test every single corner of the code. Static typing eliminates the need for type testing. In the end I see absolutely no advantage circumventing the few keystrokes it takes to explicitly write:
string x = "12"
int y = 13

Now when the programmer writes: x + y the inevitable type-error message that results is no longer something cryptic.

In the relatively rare case a programmer truly needs a variant type, it is easy enough to just use something like the object type in Heron, the cdiggins::any type in C++, and so on.

Anyway that forms the basis for my justification for explicit typing in HeronScript, and why I wouldn't teach an implicitly typed Python as a first language.

Talk Back!

Have an opinion? Readers have already posted 95 comments about this weblog entry. Why not add yours?

RSS Feed


About the Blogger



Sponsored Links

