Typing [Re: total idiot question: +=, .=, etc...]

Reimer Behrends Reimer.Behrends at p98.f112.n480.z2.fidonet.org
Wed Jun 30 14:30:49 CEST 1999


From: behrends at cse.msu.edu (Reimer Behrends)

Joshua Rosen (rozzin at geekspace.com) wrote:
> Reimer Behrends wrote:
> >         Require variables to be prefixed with "$" to denote scalar
> >         values--strings and integers, "@" for lists, and "%" for
> >         dictionaries.
> > 
> > Given the precedent of having to use self to access instance variables,
> > this is entirely consistent with the current language, and is going to
> > eliminate all those nasty problems where you can't tell from the context
> > what the type of a variable or function is. :)

> 	+There is no difficulty in getting the program to know what type
> 	some piece of data is, which lessens the need for the
> 	type-declaring prefixes--use type(), and then check
> 	obj.__class__ if obj is a class-instance, and you need to -know-
> 	what class it is (if you want to -force- it to be a certain
> 	type, keep reading).

Ahem. I happen to know Python fairly intimately after I don't know how
many years of constant use. What I wrote above was mostly a tongue in
cheek comment (heck, I even said so). The point I was making was that
the very same argument that justifies a self prefix can also be used to
justify type prefixes--in fact, I pretty much paraphrased it from an old
posting by Tom Christiansen on 10/26/98 (the message id is
<710kg1$mr0$1 at csnews.cs.colorado.edu>)

> 	+Requiring variables to bear a prefix denoting type sortof makes
> 	Python into a statically-typed language, where one of the big
> 	reasons for using it is that it's a dynamically-typed language.

I never said otherwise. But the same argument can be used mutatis
mutandum to support a "self"-less notation. :)

> 	+There is no such thing as a `scalare', in Python--strings and
> 	numbers are different data-types, numeric data can actually be
> 	one of many different classes.

I know. It was a facetious argument.

> 	+Forcing data to be of a specific type is already possible--see
> 	documentation on int(), str(), list(), tuple(), float(), long(),
> 	complex(), string.atoi(), et al. This functionality also
> 	lessens, if not completely eliminates the need for typing
> 	prefixes; the program knows what type the data is being coered
> 	into, and so does the programmer. In fact, all of the
> 	functionality that you're proposing (and then some) is already
> 	there--it just looks different.

And I just happen to be aware of that, too.

> 	+If you really want a feature that -really- isn't offered by a
> 	language, the best decision may be to just use another language
> 	that -does- offer it. Try Pike, for one (I suggest it because it
> 	has nifty typing which you may like: you can declare a variable
> 	to be one or -more- types, or use a mixed type). Choose your
> 	languages based upon what you need them to do.

And I know Pike, too. In fact, I'm pretty familiar with it.

By the way, would you mind using shorter lines next time?

				Reimer Behrends




More information about the Python-list mailing list