Does combining type add overhead.

BlitzMax Forums/BlitzMax Beginners Area/Does combining type add overhead.

ragtag(Posted 2006) [#1]
I'm working on some code, and I'm wondering if I should make a seperate TVector class, or include it as part of a TEntity class. That is should I do it like this....

Type TVector
	Field x:Float
	Field y:Float
End Type

Type TEntity
	Field t:TVector
	Field r:Float
	Field s:TVector
End Type


...or should I do it like this....

Type TEntity
	Field x:Float
	Field y:Float
	Field r:Float
	Field sx:Float
	Field sy:Float
End Type


With the first method I will need to refer to things like player.t.x and particle.previous.t.x. While with the second I can just do player.x or particle.prveious.x, but it means that I will have some extra stuff (rotation and scale, plus some methods for those) in the class those times I only need a vector.

I've actually changed my code back and forth between the two a couple of times, and can't seem to make up my mind which is the better way to go. :)

Ragnar

p.s. Thanks for the link on the Law of Demeter, the first method breaks that...but only in a way that I don't think would be problematic as the TVector class would be a very central part of the code.


H&K(Posted 2006) [#2]
Hi RagTag.

Not an answer.

I too have ummed and rrrred about this. And alternate between, all fields are base types. Or everything seperate and the field of them (Exactly as yourself)

Ive gone for your first example, (But all my fields have lot longer names). Simply on the grounds that it easyer to remember.
My opinion of overhead/optimisation at the moment, is always go for the easyest to remember with everything;
So "Player.ItsTVector.CoOrdX" (EDIT: I use ziggy's BLIDE, and the code/type completion saves loads of typeing and makes longer names more useable.)

I wanted to do the "fastest" code way. But my understanding is that means without types, and using gotos. (This might be wrong, and is definatly exagerated).
And to be honest, it takes me so long to finish anything that;
1)Using good names/types, makes the code eayer to understand (It like free rems)
2) By that time the adverage prossesor speed is probably going to be double what it is now


FlameDuck(Posted 2006) [#3]
I'm working on some code, and I'm wondering if I should make a seperate TVector class
Yes.


Dreamora(Posted 2006) [#4]
Yes you should separate.
while it has 8 byte overhead, it gives you some pro that you shouldn't miss: in case you inherit or "base class" one of your classes you could easily add another 2D vector to it or remove it without problems.

But the more important reason is that with a TVector class you can add vector operations to that class that are especially designed for it ... which is very powerfull and important for a clean OO system.