Function Overloading

BlitzMax Forums/BlitzMax Programming/Function Overloading

Blitzogger(Posted 2007) [#1]
I found a post on this stating BlitzMax does support it. The post was written 2 years ago. I need it for my game, since i want to be able to load "Single Images" and "Stript Images". The way i decided to do "persedoly" was to create 2 copies of Obj:Create with the different image loaders in each create function respectively. Does the above statement sill apply? If not how would i go about doing this?


grable(Posted 2007) [#2]
There is no support for that im afraid, but you could fake it using parameters with default values or an array parameter.


H&K(Posted 2007) [#3]
Link?

But anyway, to the best of my knowlage Bmax has never had overloading
Look at any wrapper of a C++ lib and you will see loads of
CreateFromInts
CreateFromLong
CreateFromObject
CreateFromFloataraay
etc

Overloading would be nice, but all it really does is make for shorter function/method names

(And no I dont want any examples of type pointers and the like showing Im wrong)

However, If you had your own Image Type, and you inhereted Stript Images from that, or even if you just passed your Function "objects", you could then cast back to the right Object type, so you wouldnt really be overloading, but calling the same Fucntion, but it would look like overloading.

(Unless thsi is for an engine or the like for someone else, I wouldnt bother, and would just have different names as shownabove)


Damien Sturdy(Posted 2007) [#4]
I'm not going to prove you wrong H&K, but sometimes overloading has its uses.

We are currently tackling a feature in FLOW that would be so much easier and user friendly, if Overloading (and a few other advanced OOP features..) were supported by BlitzMax.

Mark, if by any chance you catch this- please consider this feature!!!


Grey Alien(Posted 2007) [#5]
Yeah I needed overloading a few times when developing my framework. So for extended types I couldn't overload my create function I had to make a CreateSpecial function etc.


Damien Sturdy(Posted 2007) [#6]
That is exactly the issue.


Koriolis(Posted 2007) [#7]
But that particular case does NOT require overloading.
I'd call that a bug in BlitzMax.
For functions (unlike what happens with methods), which function to call is entirely resolved at compile-time, so we should be able to have two homonym functions in a base type and a derived type, even if they have different parameters. They're in different namespaces, and no dynamic dispatch is involved, so there's no problem.
Much like you can currently have 2 homonym fields in the base type and derived type.
So I'd suggest to post a bug report for that. I for one would love to see it fixed.


Damien Sturdy(Posted 2007) [#8]
Interesting point, and I agree.

I have more issues than just this though :)


H&K(Posted 2007) [#9]
@Grey,
Your framework fits in my "Engine for other ppl" bit, which I did include as the only valid reason to need overloaading.
@Cygnus
be so much easier and user friendly
Again, I get the impression that you are doing this for someone else to use.

I am honestly of the opinion, that "Intellisence" makes function overloading pointless. It was there so that you didnt need to remember what "wording" or "Paramater" an object had for its functions. But Intellisence doe that now.
Ok so in C++ it would say
"Object.Create() 1 of 5" whereas in Blide
"Object.CreateInts(Int,Int)
Object.Create.CreateIntPair (IntPair) etc"

Dont get me wrong, I would like Overloading, but its isnt needed except to reduce the size of method names

(Again, if you are writiing an Engine or the like for someone else, you might consider Overloading better from a presentation point of view)


Damien Sturdy(Posted 2007) [#10]

Again, I get the impression that you are doing this for someone else to use.



Yes. We are doing it for ease of use for you lot :P I actually said as much in the same post :P


H&K(Posted 2007) [#11]
I actually said as much in the same post
No, you just gave the impression, which is why, instead of simply assuming, let you know you never acutly said it was for someone else.
You now seem to be annoyed (:P), that I realised your intention in your "Impression"

Infact the only reason I thought that your werent making whatever it is for someone else, is that you seemed to dissagree with my first post. Even though I had specificly gone out of my way to say that it (overloading), was usful when writing stuff for someone else to use.

We are doing it for ease of use for you lot
Well, please comment on my statement that its just as easy to use non overloaded functions when you have codecomplition/intelisence, infact as object.create (1of 15) doesnt giveyou parameter information, I am now saying that not overloading gives easier to use functions/methods.


Damien Sturdy(Posted 2007) [#12]
Nono, I wasn't annoyed :) I guess I gave the wrong impression myself.


ziggy(Posted 2007) [#13]
I was annoyed! (just kidding).
I do agree overloading would be great. Something we can live without, but it would make things easy at some points. One of the things that comes to my mind would be to be able to treat colors as R,G,B values or as a single INT value.

SetColor (255,255,255)
SetColor ($FFFFFF)