How hard would it be to enhance this model to not require initialize so much? I think we could gain a static method like functionality and much more with just a couple tweaks. We need to make full use of "new" and "as". We have something similar with arrays that I use a lot because I don't like to Dim an array just to pass it to a sub so I use the "array as int(1,2,3,4,5)" type syntax where an array/list parameter is required.
I understand we need the ability to declare an object and have it null like it is now so we can store a reference to an object in it and it doesn't make sense to auto-initialize everything when it may not be used. But I see a lot of syntax like:
dim b as int: b= 3
Something would set b=0 if not set to 3 since Java doesn't do this for us, so when this is converted to Java I'm guessing it is:
int b=0
b=3
Unless the parser is specifically coded to recognize that line and changes it to:
int b=3
Now BASIC is usually a tricky language to do like Java does where we could use:
dim b=3 as int
or
dim b=3, c=4, d=5 as int
Some BASICs have done away with dim which we could do now and use local, public, private and just keeping dim for backwards compatibility. It would be cool if the = format could be used, or perhaps flip the format and do like Java declares (Probably too late in the game for this unless both are allowed)
Along these same lines though it would be easy to declare a class better:
dim myVar as new MyClass
This would then Fully Create myVar like calling:
dim myVar as MyClass
myVar.Initialize
You could call the Initialize that has parameters too like:
dim myVar as new MyClass(param1, param2)
Would be interesting to allow multiple subs called Initialize with different parameters too (Polymorphism...even if only with the Initialize sub would be excellent). In Ricky's example:
Sub Initialize
Id = 0
Thing = ""
End Sub
could be:
Sub Initialize
Initialize2(0, "") ' or Initialize(0, "") if Polymorphic Initialize allowed
End Sub
I don't claim to know all the inner workings, but the addition of the word "new" would do whatever is needed to create the object so no null pointer and calls Class_Globals, but not Initialize yet (At that point in the line). Then whatever is passed after new gets called. Then his alternate Initialize with parameters would work. Initialize2 {Initialize(id As Int, thing As String) if Polymorphic} could even call Initialize then configure other variables on its own.
In some cases you could even skip the new keyword if the sub returns the object:
sub CreateButton(text as string) as Button
dim myButton as Button
myButton.Initialize(text)
myButton.text = text
return myButton
end sub
dim ButtonView as CreateButton("OK") ' Button View is all ready to go and no need to Initialize
You could even extend this to views by adding some alternate Initialize methods in the internal classes:
' Button Class
Private EventName as string
sub Initialize
Initialize("Button")
end sub
sub Initialize(EventPrefix as string)
EventName = EventPrefix
end sub