LISTSERV mailing list manager LISTSERV 16.0

Help for MASON-INTEREST-L Archives


MASON-INTEREST-L Archives

MASON-INTEREST-L Archives


MASON-INTEREST-L@LISTSERV.GMU.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

MASON-INTEREST-L Home

MASON-INTEREST-L Home

MASON-INTEREST-L  October 2009

MASON-INTEREST-L October 2009

Subject:

Re: Double2D and MutableDouble2D Conundrum

From:

Matthew Berryman <[log in to unmask]>

Reply-To:

MASON Multiagent Simulation Toolkit <[log in to unmask]>

Date:

Thu, 29 Oct 2009 20:19:49 +1030

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (125 lines)

Sean,

I agree with your points on (B), and this would be personally least  
surprising to me, given the other existing methods (it is mutable,  
after all :)
I'm just a sample size of one, though.

Cheers,
Dr Matthew Berryman
Defence and Systems Institute
SPRI Building
University of South Australia
Mawson Lakes  SA  5095
t +61 8 8302 5882
f +61 8 8302 5344
m +61 413 458 594
CRICOS Provider Number: 00121B



On 29/10/2009, at 7:40 PM, Sean Luke wrote:

> Not hearing a peep from the peanut gallery :-( I'm inclined to make
> the (B) modifications.  Going once, going twice?
>
> Sean
>
> On Oct 27, 2009, at 7:41 PM, Sean Luke wrote:
>
>> I'm facing a tough decision on Double2D which could affect the
>> entire community and so I'm interested in some feedback.
>>
>> I've been going through the physics2d engine and doing some cleanup
>> and one thing that could really help in that cleanup is to add some
>> functions to Double2D which are presently only in MutableDouble2D,
>> but to do so in such a way that Double2D's version would have
>> somewhat different semantics.
>>
>> MutableDouble2D has four kinds of ways of "adding":
>>
>> MutableDouble2D m1, m2, m3;  // 2d vectors
>> double v;  // a scalar
>>
>> m1.addIn(m2);   // m1 <- m1 + m2, return m1
>> m1.addIn(v);    // m1 <- m1 + v (at all slots in m1), return m1
>>
>> m1.add(m2, m3); // m1 <- m2 + m3, return m1
>> m1.add(m2, v);  // m1 <- m2 + v (at all slots in m1), return m1
>>
>> The use of "add" in this context is unfortunate, I know.  It's going
>> to cause problems in a second.  But originally my idea was to enable
>> stuff like this:
>>
>> m1 = new MutableDouble2D().add(m2, m3).multiplyIn(v).normalize();
>>
>> Which does
>> 	m1 <- normalize((m2 + m3) * v)
>>
>> ... but doesn't do any new allocations at all, because at each step
>> we just overwrite the variables inside the MutableDouble2D we  
>> created.
>>
>> Okay, so that's cute.  The problem comes when I want to add similar
>> functionality to Double2D.  I can't implement an "addIn" method
>> because Double2D is IMMUTABLE.  Instead, I'd do something like this:
>>
>> Double2D d1, d2, d3;
>> double v;
>>
>> d1 = d2.add(d3).mutiply(v).normalize();
>>
>> This does the same thing but at each step a new Double2D is
>> created.  For example,
>>
>> d1.add(d2);	// new d <- d1 + d2, return d
>>
>> That's a good, easy to understand functional style which is much
>> less convoluted than the MutableDouble2D approach, BUT it allocates
>> lots of Double2Ds, which isn't particularly efficient, though it's
>> not horrible.  So it's a useful functionality to have in Double2D.
>>
>> The problem is that the semantics are somewhat different than
>> MutableDouble2D's semantics, in which the original object is
>> OVERWRITTEN.  This is particularly obvious in the normalize()
>> method, which in MutableDouble2D normalizes the actual
>> MutableDouble2D, but for Double2D would produce a new Double2D (it's
>> have to).
>>
>> Also MutableDouble2D's add(...) method, for example, takes two
>> arguments and has totally different semantics than Double2D's
>> add(...) method would.
>>
>> I'm trying to nail down what options I have.  One choice I have been
>> mulling over is to add methods to Double2D like add(d) [note one
>> argument], multiply(v), etc., and then also create similar
>> MutableDouble2D methods with the same names.  But the question is
>> how the MutableDouble2D methods should work.  Should they (A)
>> produce NEW MutableDouble2D instances or (B) overwrite the existing
>> MutableDouble2D instance, like other MutableDouble2D methods
>> presently do?
>>
>> (A) is more semantically consistent with the proposed new Double2D
>> methods.
>>
>> (B) is semantically consistent with the existing MutableDouble2D
>> methods.
>>
>> I'm trying to follow the principle of least surprise but I don't
>> know which of these would have less surprise.   normalize() in
>> particular will *have* to be case (B).  There's no way around it.
>> Which has been nudging me to wards doing (B).   A third option would
>> be to just create Double2D methods and not create ANY equivalent
>> MutableDouble2D methods.
>>
>> The decision made here will have a long-standing effect on use of
>> these classes, and they're so integral to MASON that I want to be
>> very very careful.  Backward compatability will be retained but I am
>> concerned about making things weird in the future.
>>
>> So I'd really appreciate some opinions on the matter.
>>
>> Sean
>>
>>

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2021
May 2021
April 2021
March 2021
February 2021
August 2020
July 2020
June 2020
February 2020
August 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
October 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
September 2017
June 2017
May 2017
March 2017
February 2017
January 2017
December 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
February 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
July 2004
May 2004
April 2004
March 2004

ATOM RSS1 RSS2



LISTSERV.GMU.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager