«« Urgent My Foot! Coke vs Coffee »»
blog header image
Strong vs Weak Typing

As someone that has used strongly typed programming languages for most of his short career, I'm finding it hard to grasp the advantages of weakly-typed ones.

Paul Vick makes a good point when he says that generics make strongly typed languages even stronger, and this seems to go straight against the new wave of weakly typed languages like Python and older ones like Smalltalk.

It seems somewhat related to the enabling vs. directing thread that was going around recently. Strongly typed languages direct you down an inflexible path: you may only assign a value of type A to a variable of type A or one of its superclasses or interfaces. Once you do that it may be painful to change the type later in the code because you have to edit all of the types. Weakly typed languages enable agile processes where a value's type may change often and variables don't have type. Good unit testing with weakly typed languages prevents programmers from making mistakes with types.

Refactoring support in IDEs like Eclipse digs into this advantage of weak typing though. If I can change the strong type of a variable everywhere in the code with one action then isn't this the same difficulty as changing a weak type except now I have a more rigid type contract? If the tools enable the same type flexibility as weakly typed languages wouldn't a strongly typed language be better?

Maybe I need a few examples. I haven't seen the light yet.

Update 7:30 PM as James Robertson points out I'm way off base here. That'll teach me for thinking out loud. :) I won't correct my post though -- it's already been linked to.

Yep, I really meant to ask: what is the advantage of dynamic typing over declarative typing?

Posted at March 27, 2004 at 03:50 PM EST
Last updated March 27, 2004 at 03:50 PM EST
Comments

Ryan, Python and Smalltalk are strongly, dynamically typed languaged - if you call a method on an object which doesn't implement that method, you get a specific behaviour (which is usually to raise an exception). In C, a weakly typed language, if you try and dereference a null pointer, all you get is a segmentation fault.

» Posted by: Giovanni Corriga at March 27, 2004 07:07 PM

OK, so I'm mistaking what strong and weak types are. I'm actually referring to dynamic and static typing then.

What are the advantages of dynamically typed languages?

» Posted by: Ryan at March 27, 2004 07:27 PM

The best way to learn about the benefits of a dynamically typed programming language is to play with one! You might check out MzScheme or Squeak (implementations of Scheme and Smalltalk-80, respectively). Programming in those languages is a totally different experience than programming in a statically typed language like Java or C#.

Some people find it easier to learn (and teach) dynamic languages because precisely because they lack a strong definition of "type". For people new to computer science, types can be a really hard concept to grasp. Dynamic languages don't require you to care about type as a formal concept unless you want to, so you're free to focus on more fundamental concepts (iteration, recursion, procedural abstraction) without getting into the nebulous and confusing world of types.

» Posted by: Steve at March 27, 2004 08:25 PM

I'm kind of comfortable with types. It might be hard to get out of that paradigm ... but I'll try. :)

» Posted by: Ryan at March 27, 2004 09:19 PM

"The Computer Science and Engineering Handbook" at least provides some consistent terminology; so we can talk about static-type-checking and dynamic-type-checking, explicit types and implicit types, and languages that are type-safe and those that aren't.

http://citeseer.ist.psu.edu/cardelli97type.html

» Posted by: Isaac Gouy at March 27, 2004 09:58 PM
Google
 
Search scope: Web ryanlowe.ca