Python for air traffic control?

Michael Ströder michael at stroeder.com
Wed Jul 4 00:25:17 CEST 2001


Russ wrote:
> 
> Consider the type checking in C or C++, for example. Suppose that a
> function takes several ints (or any other type) as arguments, and
> suppose the calls of the function all pass ints in the correct slots.
> The compiler will be perfectly happy. Does that assure that the
> arguments are passed correctly? Of course not.

Did you ever used Modula 2 or at least Pascal? I used to declare
types for almost every integer index I had to pass to a
function/procedure. Type checking in C/C++ is almost meaningless
compared to that.

> Now consider argument passing by keyword in Python. The order of the
> arguments no longer matters. Sure, the wrong type of arguments could
> still be passed in, but it seems to me the probability is less than
> getting the wrong object of the right type in C++. In C++, the
> complier only checks the type of the argument, but Python checks the
> actual NAME of the argument. The name is more specific than the type.

Just a rough idea: How about pass instances with the parameter
values stored in the class' attributes named differently. IMHO this
would reduce the probability of passing wrong arguments even more.

> As I said, static type checking is a must, but it can already be done
> in Python.

An method/function implementor could also check the type of every
argument passed if the interpreter is started in debug mode. You can
mandate to comply with a style guide.

if __debug__:
  if type(arg1)!=type(''):
    raise TypeError,'Argument arg1 must be string type.'
  if type(arg2)!=type(1):
    raise TypeError,'Argument arg2 must be integer type.'
  ...

Ciao, Michael.



More information about the Python-list mailing list