Python Lint? (was "Can Python supplant Java?")

Terry Hancock hancock at anansispaceworks.com
Fri Aug 23 10:40:49 CEST 2002


From: Webb Sprague <wsprague100 at yahoo.com>
> It seems to me that it would be pretty easy to address
> the type checking question by some thing like the
> following:
> 
> When you are going to use a variable, assign it a
> default in the appropriate type (stringv = '', intv =
> 0, etc).  Run the Python script through a lint type
> program that would flag any variables assigned to
> without such a "declaration" or any variables assigned
> a new type.
> 
> I have been helped by Perl's "use strict;" / "my"
> feature many times.  My idea might approximate it.

I've never actually encountered a bug that would've
been solved by type-checking (in Python), but if I
need to be sure I had a certain type, I'd probably
do something like:

def myfunc(a, b):
	assert type(a)==type(1.0)
	assert type(b)==type(1.0)

	return a/b

True, this will only do the type checking at run
time, but I can't think of any real situation in
which that wouldn't be good enough.

It would perhaps be nice to do static type checking
(optionally), like this:

def myfunc(float a, float b):
	return a/b

and indeed, Pyrex has a construct very like this.
Doing so would require quite a bit of change, I
think. Pyrex does it because it's actually compiling
a C function underneath, and so static typing makes
sense.  In Python though, I would suspect it would
be hard to be certain what type a and b are (except
at run time, when it's easy).

If internal data representation is important, I
imagine Python is a bad choice -- that's where
using C in one form or another becomes attractive.
Python is a *high level* language, and I think
it benefits from leaving lower level jobs up to
languages better suited to the task.  Don't use
a sledgehammer to do a toothpick's job, nor vice-
versa.

Regarding the initial argument, I suspect Java is
probably closer to the latter category, along with
C/C++, which is surely the philosophy behind the
Jython developers, since they are mapping C's role
to Java.  That being the case, I doubt Python will
"supplant" Java, though it may narrow its
application, as it has done for C. For me the
choice is more of availability than pure merit.
There are places where I can expect a JVM, but not
a python interpreter.  Then there's legacy applications --
there's a lot of stuff designed for Java already,
but not (yet?) available for Python. If I want
to use it, I guess I'll be using Java.

Anyway, I don't know Java yet, but I'm learning it,
*after* learning Python, so obviously I think there
are applications.

Cheers,
Terry

-- 
------------------------------------------------------
Terry Hancock
hancock at anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
P.O. Box 60583                     
Pasadena, CA 91116-6583
------------------------------------------------------




More information about the Python-list mailing list