[Tutor] Dynamic/Weak Types and large projects

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 30 Jul 2002 08:09:57 -0700 (PDT)


On 30-Jul-2002 anthony.barker@bmo.com wrote:
> 1) Dynamic vs Weak Types
> 
> I have heard python referred to as having "weak" types - how does this 
> differ from "dynamic types" ?
> 

input = '42'   # I am a string
i = int(input) # I am now an integer
i = '83'       # oops I am a string again

Python has types.  string, integer, float, list, tuple, dictionary.

d = {}
l = []

if you do:

d = l # I am allowed but the dictionary is forgotten

hence "weak" types.  In say C++ that never would have compiled because the
pointers would have been of different types.

> 2) General consensus is that for large projects strongly typed languages 
> are better.
> Is there any statistical proof of this beside hearsay?
> 

I am uncertain if this is still true.  I do not know of any clear documentation
of this.

However my above examples is definately something that a strong type person
would use to point out a failing in python.  He would say look how easy it is
to assign the "wrong" values to a variable.  The key difference is in python
almost all errors are noticed at runtime whereas strong type languages can
catch problems at compile/parse time.  So a problem is known much earlier.  In
a large project being able to reproduce a runtime error can be quite difficult.

In the end you weight the pros and cons.  Is stronger up front handling more
important to you than python's other features?  dynamic and weak allows for
some great flexibility and often really clean and ingenious solutions to
difficult problems.