Why no number methods?

Magnus Lie Hetland mlh at idi.ntnu.no
Mon May 14 09:07:03 EDT 2001


"Michael Hudson" <mwh at python.net> wrote in message
news:Pine.LNX.4.30.0105141203140.24801-100000 at localhost.localdomain...
> On Mon, 14 May 2001, Magnus Lie Hetland wrote:
[...]
> As said above, no real reason.  It's not obvious to me that it buys one
> much though (this could be because strings have more in the way of
> internal structure than floats or ints - if you know the value of a
> number, that's about all you need, whereas it's reasonable to ask a string
> "how many 'e's are there in you".  Just waffling, but there have been
> times I'd have liked a .bitlength() method on longs).

I guess I agree that it isn't all *that* useful... I just nostalgically
remember SmallTalks uncompromisingly consistent mechanism -- and noticed
that Ruby was quite similar... I just think it would be neat to be able
to explain the main syntax/semantics in a few lines (such as the
object calculus of Abadi & Cardelli in "A Theory of Objects"). I do
it the other way around in "Instant Python" and "Instant Hacking",
starting with simple/intuitive imperative programmin, and adding
classes and methods almost as an afterthought. This was motivated by
my perception of classes and methods as an afterthought in Python,
althought I'm sure that's an unfair characterisation.

> If 2.2 == 3000 (I don't think fp arithmetic is *that* inaccurate <wink>)
> you *may* get your wish.

Well -- from Guido's preface to the newest "Programming in Python"
this seems highly unlikely ;)

> Check out (in more sense than one) what Guido's
> been doing on the descr-branch in CVS recently.

Hm...

> One of the implications of the descr-branch is that it becomes possible to
> subclass built-in types.

This is the most desirable version, of course (IMO)
(even *without* any methods ;)

> A foolish consistency is the hobgoblin of little minds?

Perhaps. In my opinion, a lack of consistency is worse...
In this case I guess it's a matter of how many basic concepts
you want to have (or "pretend" to have, in the face of a newbie ;)

> It has to be
> said, I don't conceive of the operation
>
> 1 + 2
>
> as passing a message "__add__" to the integer object "1".

Neither do I, since that's not what's going on. In SmallTalk, however,
I *do* perceive it more in that manner (although I'm sure the call
is optimised away ;)

> But I concede
> that it's a valid viewpoint, and an area where Python is somewhat
> inconsistent today.

Yes. One of the reasons that I dare hold such a viewpoint is that the
BDFL himself has as an expressed goal to make all objects have classes
(including all the builtin type objects, such as numbers) -- he's just
not there yet.

> > (I mean, I can get quite a long way with lists and strings, but...)
>
> Bah, all you need is lambda & Church numerals <wink>.

Yes, certainly. I could start with that. :)

> Did you read my last python-dev summary?

Errr... No. Perhaps I should?

>
> Cheers,
> M.
>

--

  Magnus Lie Hetland         http://www.hetland.org

 "Reality is that which, when you stop believing in
  it, doesn't go away."           -- Philip K. Dick






More information about the Python-list mailing list