[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] vector type: mutable or immutable
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] vector type: mutable or immutable
- From: Stuart Axon <stu.axon+pygame@xxxxxxxxx>
- Date: Fri, 1 May 2009 15:13:56 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Fri, 01 May 2009 10:13:59 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=t9XhXLCfnZYpNgvbRnzlQ8bLRrDQkPAZlRtAn2EZOgo=; b=ufQuJT4ely6QIHFKIlLUSue4MezaNjWRBVDBCH8F7o0DlV0bS4NZ8sW40FZx/s4s69 5p4qig3VAgkFLfzopados0/qFcXnMY8LqrtvfS2xM5scHFr6EQRFoaV+GBN/edGzCWw1 Je8kasAsEpo0LDEOm25K7Ml6Q9ILFP2UVp2+w=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=OPr8ce0Hc7z0E1mjDDQ03dLfM0gaR9b4wqVnvxF8Y4FgNMjh5hPxeF35FyGq+27iyH vU5V0vanTH89QhNsoBn2Wam+R74uY/k9hf4R5iGftQS2zCSgT4Lj1JAIbL6F0++63Z/F M6n58STN5qFzlPl+ttejlwCre+f2T0KG2jijk=
- In-reply-to: <49FB020A.2030900@xxxxxxxxxxxxxxxxx>
- References: <49FB020A.2030900@xxxxxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I guess mutable is more consistent with the rest of the api (things
like rect IIRC)
2009/5/1 Lorenz Quack <don@xxxxxxxxxxxxxxxxx>:
> Hi
>
> as a follow up to the "API draft for vector type" I would like to discuss
> the merits of having a mutable or immutable vector type.
>
>
> Arguments for an immutable vector type:
>
> Brian Fisher pointed out two advantages of immutable vector types:
> 1) they prevent bugs in programs like the following (adopted from Brian):
>> class Angel(object)
>> def __init__(self, offset):
>> self.offset = offset
>>
>> t = Angel()
>> halo_pos = t.offset
>> halo_pos.y -= 5 # BUG: this changes the offset in t
>
> 2) if vectors are immutable you can use them as keys in dicts
>
>
>
> Arguments for a mutable vector type:
>
> 1) operations such as rotate() and scale_to_length() are more elegant when
> operation in-place. for immutable types you would have to do "v =
> v.rotate()" or use a module level rotate function "v =
> pygame.math.rotate_vector(v)" or something similar.
>
> 2) a priori I would expect mutable vectors to perform better than immutable
> ones because you don't have to create new objects for every operation.
>
>
>
> So are there anymore arguments?
> And where do people stand on this issue?
>
>
> yours
>
> //Lorenz
>