Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: mutable ints: I think I have painted myself into a corner

Reply
Thread Tools

Re: mutable ints: I think I have painted myself into a corner

 
 
Cameron Simpson
Guest
Posts: n/a
 
      05-19-2013
On 19May2013 11:11, Chris Angelico <(E-Mail Removed)> wrote:
| On Sun, May 19, 2013 at 10:26 AM, Cameron Simpson <(E-Mail Removed)> wrote:
| > Before I toss this approach and retreat to my former "object"
| > technique, does anyone see a way forward to modify an int subclass
| > instance in place? (That doesn't break math, preferably; I don't
| > do arithmetic with these things but they are, after all, ints...)
|
| Why is it an int subclass? Because there are places where you want to
| use it as though it were an int? It might be easier to render those,
| instead, eg by creating a __int__ method. (Or is it "an __int__
| method"? Not sure.)

I don't want to use it as an int, on the outside. I want to use an
int on the inside as the implementation.

It's an int _subclass_ so that it is no bigger than an int. Otherwise
I may as well just make an ordinary object and be back where I
started. Bulky

The reason it is an _int_ subclass, versus something else, is that
a bitmap is a type of int. So the functional mapping is direct.

I _do_ _not_ want to operate on it from the outside as an int (doing
overt addition, for example, though I can imagine doing bitwise
activities); I want to operate on in _internally_ as a int to decide
what names-by-an-attribute flags are on or off.

So an object with an __int__() method is right out; it's the wrong
interface because it would mean an int() call (possibly implicit)
in exterior code.

Cheers,
--
Cameron Simpson <(E-Mail Removed)>

Hoping to shave precious seconds off the time it would take me to get
through the checkout process and on my way home, I opted for the express
line ("9 Items Or Less [sic]" Why nine items? Where do they come up with
these rules, anyway? It's the same way at most stores -- always some
oddball number like that, instead of a more understandable multiple of
five. Like "five.")
- Geoff Miller, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Gregory Ewing
Guest
Posts: n/a
 
      05-20-2013
Cameron Simpson wrote:
> It's an int _subclass_ so that it is no bigger than an int.


If you use __slots__ to eliminate the overhead of an
instance dict, you'll get an object consisting of a
header plus one reference, which is probably about the
size of an int. But you'll also need an int to put in
that slot, so the total size will be about twice that
of an int.

Another approach would be to subclass array.array and
give instances of it type integer and size 1. Together
with empty __slots__, it will probably be a bit bigger
than an int, but it might still be smaller than a
custom object plus an int.

If all of these are still too big, you might need to
find some way of packing multiple instances into a
single array.array.

--
Greg
 
Reply With Quote
 
 
 
 
Cameron Simpson
Guest
Posts: n/a
 
      05-20-2013
On 20May2013 13:23, Greg Ewing <(E-Mail Removed)> wrote:
| Cameron Simpson wrote:
| >It's an int _subclass_ so that it is no bigger than an int.
|
| If you use __slots__ to eliminate the overhead of an
| instance dict, you'll get an object consisting of a
| header plus one reference, which is probably about the
| size of an int. But you'll also need an int to put in
| that slot, so the total size will be about twice that
| of an int.

Yeah, I was thinking I'd need to go that way. Thanks for the
suggestion.

| Another approach would be to subclass array.array and
| give instances of it type integer and size 1. Together
| with empty __slots__, it will probably be a bit bigger
| than an int, but it might still be smaller than a
| custom object plus an int.

Really? Interesting. I thinik it crosses my "too baroque" threshold,
but maybe not

| If all of these are still too big, you might need to
| find some way of packing multiple instances into a
| single array.array.

Space isn't that real an issue at present; I'll keep that kind of
approach in mind if it comes up. This really came up because I was
feeling that the obvious object-with-boolean-attributes was terrbily
wasteful for something that can be inplemented with a single int,
in principle.

Cheers,
--
Cameron Simpson <(E-Mail Removed)>

>>>How do you blip the throttle and wave? Do you blip it real high, then wave
>>>before the revs drop back?

>>Blip = right hand; Wave = left hand. Do both simultaneously. QED.

>Doesnt this make the bike lurch forward thru the intersection?

Not if the disk lock is in place...
- Dean Woodward <(E-Mail Removed)>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: mutable ints: I think I have painted myself into a corner Chris Angelico Python 0 05-19-2013 01:11 AM
mutable ints: I think I have painted myself into a corner Cameron Simpson Python 0 05-19-2013 12:26 AM
painting myself into a corner !help! Dave Rose Ruby 2 04-19-2007 09:02 PM
? dimensions of a JPanel before it's first painted? TL Java 4 08-03-2004 02:44 AM
I've painted myself into a corner! JustSomeGuy C++ 4 06-23-2004 09:29 AM



Advertisments