anomaly

Chris Angelico rosuav at gmail.com
Sun May 10 21:53:24 EDT 2015


On Mon, May 11, 2015 at 11:18 AM, zipher <dreamingforward at gmail.com> wrote:
> Okay.  I apologize for thinking in C and believing "int" was a keyword.  It isn't in Python as you remind me.  However, this is where I'm arguing the purity has hammered practicality into the ground.
>
> Python is trying to be as elegant as LISP in trying to make everything an Object.  It's not necessary, and it's trying to put lipstick on a pig instead of making BBQ.  Python will be as elegant, but in a different direction of the axis.
>

How is it a problem for an integer to be an object? In Python, I can
put together a generic handler for a generic list and depend on
everything being an object:

lst = ["asdf", 2, lambda x: x+1, re.compile("q[a-tv-z]"), 3.14159]

In Java, I would have to box up that integer 2 and that float 3.14159
(and maybe the string too?) to make it possible to put them into a
generic collection, because integers and objects are fundamentally
different things. In Python, ints and floats and strings all follow
the same rules as other objects: they can be passed around, stored in
collections, turned into strings with str() or repr(), etc, etc, etc.
They have methods, they react to operators, everything is done
according to a simple set of rules. This does not harm practicality -
it's extremely helpful in a number of situations.

And I still don't see how this has anything to do with your confusion
about shadowing the name 'int'. As I see it, attempting to redefine
int to be a null subclass of str should have one of two results:
either it's a straight-up error, or it does exactly what happens in
Python - calling 'int' now calls a subclass of 'str'.

ChrisA



More information about the Python-list mailing list