Re: [BLACKBOX] LibVector question

From: [at]} <Robert>
Date: Fri, 27 Mar 2009 21:13:54 +0000

----boundary-LibPST-iamunique-1977745057_-_-
Content-type: text/plain

Wojtek Skulski wrote:

> Meanwhile I have a question. Your function LibVectors.Neg is allocating
> a new vector. Why? Flipping the sign of every vector element can be done
> in situ. Why are you calling NEW?

And the same comment applies to other functions, such as Abs, Mag, Map etc.

One has to make design choices, which usually have pros & cons. It is rare that
one choice is superior from every aspect.

I assume you have read the section in the Docu called "Assignments".

The issue is:

VAR
   a, b : LibVectors.Vector;
BEGIN
   a := .....;
   b := a;

   LibVectors.Neg (b);


If this was in-place it would also negate the 'a', whereas with
my design:

   b := LibVectors.Neg (b); (* Neg inclueds a NEW *)

I have negated b without the non-obvious side effect of negating a.

I think this is safer, less prone to accidental error.

It is not 'completely safe'; to do that Vectors would have to be immutable with
their components set to be Read-only (somehow). This I considered too
inconvenient and inefficient, hence the design compromise you see.


By contrast the design philosophy for the type LibComplex.Complex is 'safe'; the
type is immutable, the fields are read-only, and 'Big' sums with Complexes
generate a lot of garbage.


I am sure there are applications where these design choices are sub-optimal, if
not unacceptable. But that would be true of any choice. C'est la vie.


Cheers

Robert


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1977745057_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1N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N1Yi1vcHRpbWFsLCBpZiBccGFyDQpub3Qg
dW5hY2NlcHRhYmxlLiBCdXQgdGhhdCB3b3VsZCBiZSB0cnVlIG9mIGFueSBjaG9pY2UuIEMnZXN0
IGxhIHZpZS5ccGFyDQpccGFyDQpccGFyDQpDaGVlcnNccGFyDQpccGFyDQpSb2JlcnRccGFyDQpc
cGFyDQpccGFyDQotLS0tXHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGgg
Ym9keSAiU0lHTk9GRiBCTEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIfX0AAAAA
NQ==
----boundary-LibPST-iamunique-1977745057_-_---
Received on Fri Mar 27 2009 - 22:13:54 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:48 UTC