Function wrapping?
BlitzMax Forums/BlitzMax Programming/Function wrapping?
| ||
I have a UDT called TFoo which contains a function called Bar() like so:Type TFoo Function Bar( xyz:int ) 'Code and stuff End Function End TypeNow I wish to also wrap this function so it can be used as FooBar(). As far as I can tell there are two ways I could do this. Version 1: Global FooBar( xyz:int )=TFoo.BarVersion 2: Function FooBar( xyz:int ) TFoo.Bar xyz End FunctionNow my question is what are the pros and cons of each version? Should I be using v1 or v2, or does it not matter? |
| ||
I'm guessing v1 is fastest. Why not just put the Bar function outside TFoo in the first place? |
| ||
It's an organisational thing. I like to keep all the code for my types self contained, but I'm not fond of using functions as TFoo.Bar(). I find FooBar() much more readable than TFoo.Bar() when I'm skimming through my code. This is also true for the type's globals consider:Type TFoo Global x:Byte Global y:Byte Global z:Byte Function Bar( xyz:Int ) x=xyz y=xyz Shl 8 z=xyz Shl 16 End Function End Type Global FooBar( xyz:Int )=TFoo.BarVs. Type TFoo Global x:Byte Global y:Byte Global z:Byte End Type Function FooBar( xyz:Int ) TFoo.x=xyz TFoo.y=xyz Shl 8 TFoo.z=xyz Shl 16 End FunctionNow the difference isn't much in such a small example, but I find the first method much more comfortable with more complex code. |
| ||
I would guess #1 in the first post is faster too. As for your second post, I would use TFoo.Bar and neither one of your examples. I realize you do not want to do it, but basically, you are taking an Object Oriented language and using it Procedurally. To each his own, I guess. |