Overloading Functions?

BlitzMax Forums/BlitzMax Programming/Overloading Functions?

Drey(Posted 2006) [#1]
Type Template
	
	Method Action()	Abstract 

End Type

Type MyType Extends Template

	Method Action( X:Float Var )
	
		Print X
		
	End Method
	
End Type 



If so..blitz seriously needs to add this functionality.


H&K(Posted 2006) [#2]
Bmax, needs the overridding functions and Methods to have the same footprint.
So no it doesnt have overloading


Drey(Posted 2006) [#3]
Hmm...why would he not impliment overloading?


Gabriel(Posted 2006) [#4]
Probably because of BlitzMax's automatic typecasting. It could become rather ambiguous which method should be called, and which method would be called. I like overloading, and I've probably requested it in the past, but you asked why, and that's my guess as to the reason.


H&K(Posted 2006) [#5]
Overloading is a precompiler thing, so hassle ziggy to put it in Blide


Dreamora(Posted 2006) [#6]
Why should it actually be in?
You have 2 method with different input, so they most likely do different stuff which means you should use different methods from OO point of view, as one method means one operation, not 20 different operations but one name (as C++ thinks its needed to do)

Another way is giving the int input to the base method as well and just give it a default value for example.


Drey(Posted 2006) [#7]
Because i just wanted to use a template for forcing current methods to be made.

ANyhow. Here's the situtation

I have a template. As i extend more vector variables.

I want the is-a relationship to kick in.

Vectemplate->Vec->Vec2->Vec3->Vec4

So if vec4.add(vec2). The vec2 of vec4 variable and instead just add x,y instead. IT just saves the programmer time. Cutting typing to save characters on meaningful names is different than having efficient programming language.

I am aware of the ways around it. Just shouldn't have to do the extra coding if it can be prevented.


PGF(Posted 2006) [#8]
<Sarcasm>
And why on earth does BlitzMax have variable names? I mean they are just a way of referring to memory locations so why not just hard code the address?

Types? Hey you should know what the data means without all that pinko compiler type safety rubbish.

Arrays? Hah just an offset to a memory location.

Functions? Give me a break! Just push your arguments and return address and jump to the instructions in memory. You're lucky enough to have a stack buddy.

Programmers these days just one all the hard stuff done for them.
</Sarcasm>

Method overloading and proper constructors are really good things that I still wish for in BlitzMax. Its been over a year. Maybe some day.


Grey Alien(Posted 2006) [#9]
I'd like to see it too.


Dreamora(Posted 2006) [#10]
Drey: Where is there actually a problem with yours?

If you define the Add within the Vectemplate then you can add anything. And if you use an array for the actual values with methods to get / set you don't even have a problem on add etc as you can simple do for local i:int = 0 to min(vec1._data.length,vec2._data.length)


H&K(Posted 2006) [#11]
@Dray,

Im getting really annoyed with people making me agree with Dream. The situation you have described is a one of casting, not of Overloading.

Whereas I would quite like Overloading, All its loss does is mean I have really long Function names.
Function BobAddIntIntFloatInt() (Dont forget with overloading you still have to write all the seperate functions and methods.
What you have asked for thou is for a function to accept a aprrameter, and then accept a parameter that is an extention of the first parametter. Bmas does this. The problem then is knowing which "Extentioned" parametter you are using. But there have been lots of posts about this.

(If Ive missunderstood, and you want to send as a parrameter an unsepcific number of vectors, then sent them as members of an array)


ziggy(Posted 2006) [#12]
Don't you thing it would be a good idea to request for an array-parameter style,I mean;

Function MyFunciton(Value as String() ParamArray)
....
....
End Function

MyFunction("Hello","wait","Draw","play")



FlameDuck(Posted 2006) [#13]
Don't you thing it would be a good idea to request for an array-parameter style
No, because it would be silly to request a feature that was already there.

But generics (or rather, specifics if you want) annotation, and reflection would all be useful additions.


AlexO(Posted 2006) [#14]
One application of this would be the writing of streams. While blitzmax has a WriteInt(),writestring(),writefloat() methods for streams, if you had overloading you'd just have a Write(var:type) method. Sure, you'd still have to define all of them, but as another programmer uses it they don't have to wonder what naming convention you used for your method names and they just have to pass the variable in and it'll write itself to the stream.


Dreamora(Posted 2006) [#15]
Actually this stuff is in. You just have to have your object extend TData which is the "coretype" to write to streams and will be able to read and write objects to a stream. (you will need to implement some methods)


AlexO(Posted 2006) [#16]
Interesting. I'll have a look at that later tonight then.