dynamic typing questions

Eli Pollak eli456123 at hotmail.com
Sun Dec 21 23:29:39 CET 2003


> > The other programmer here is very concerned
>about
> > dynamic typing though in Python.  He feels like
>this
> > would be too much of a hinderance on us and too
>easy
> > for us to make a mistake and not catch it until
> > runtime making debugging harder.
>
>One problem with static typing is that the type
>you want is too often not one of the types you
>have immediately available.  It may be a subset or
>union thereof.  If log(-1.0) passes the compiler,
>then you get a runtime crash that is at most as
>graceful as Python's default traceback.  If log(1)
>does not pass the compiler (if it does not
>autocast to float), then you are delayed until you
>stick in the 'missing' decimal point.
>
>The corresponding advantage of Python's dymanic
>typing is that functions are generic; they work
>with any data that works and is not specifically
>excluded.  C preprocessor text macros such as
>(untested, written from years ago memory)
>
>#define max(a,b) ((a) > (b) ? (a) : (b)) /* beware
>of double side-effects */
>
>that implement generic pseudofunctions testify to
>the usefulness of this.
>
>Terry J. Reedy


I find the same problem.

I have to check the type of every parameter of every method to ensure 
unbreakable code. php5 has something I think would be nice in python. they 
call it 'type hinting'.

class blah:
  def fn(self, int num, obj): # declare num to be of type int, but obj is 
dynamically typed
    # do something

such that you can optionally put in the type and it will be checked for you. 
This would save me alot of what I think is unnecessary parameter validation, 
yet allows dynamic typing if you want to use that instead.

Cheers
Eli

_________________________________________________________________
Get less junk mail with ninemsn Premium. Click here  
http://ninemsn.com.au/premium/landing.asp






More information about the Python-list mailing list