Fields : Types vs 'normal'
BlitzMax Forums/BlitzMax Beginners Area/Fields : Types vs 'normal'
| ||
What are the pros/cons of doing this :Type ttest1 Field pos:tvector2d = tvector2d.create() End Type Type tvector2d Field x:Float=100.0 Field y:Float=100.0 Function create:tvector2d() Return New tvector2d End Function End Type as opposed to this : Type ttest2 Field posx:Float = 100.0 Field posy:Float = 100.0 End Type temp1:ttest1 = New ttest1 |
| ||
Pro: You could add vector functionality to the vector type. This would otherwise need to be external functions which isn't as clean as objects. Con: you have a little overhead due to the "object" part. Way one needs a little prethinking: 1. You need pooling. Without it you will kill your app most likely (there is a very usefull thread somewhere on the boards on optimizing) 2. Its highly suggested to implement 2 versions of all operations. an "in-situ" version (that changes the object itself) and a return version that returns a resulting vector which holds the data of the operation. Reason here is that there are cases where you need a result and cases where you want to modify the current. (for example normalize is such a functionality that needs both normally. once where the vector itself is changed and once where you need the normalized vector for vector projection and the like) |
| ||
I tend to add another level, wereby the function create (when given parameters), then calls the method set, passing the parrameters. |