BlitzMax Language Design

BlitzMax Forums/BlitzMax Module Tweaks/BlitzMax Language Design

Punksmurf(Posted 2006) [#1]
For quite a while I've been wondering why BlitzMax is not using Objects all the way.

Some modules, like the List-module, are completely useable using OO. myList.this, myList.that, you can do it all. However, there are also some global functions, like ListAddLast(). Why is that function in there? I think it's really bad practice to use it. Not to mention the fact that most of it is not very well documented...

This, however, is not the worst thing. Some things, like graphics, aren't easily handled as objects. You can make a graphics object (canvas.TGraphics = CreateGraphics... (which, imo, SHOULD be canvas.TGraphics = TGraphics.CreateGraphics)), but you can't use canvas.setAlpha or something like that; you should use a global function setAlpha.

I think this is really messy, or am I missing some point here?


CS_TBL(Posted 2006) [#2]
I think the point is to offer a comfortable interface towards traditional basic users.. it *is* a Basic we're talking about eh.. (well, Basic++ I'd say :P)


Punksmurf(Posted 2006) [#3]
I agree with you that it's nice to offer a comfortable interface, but my main problem is that I have to use this 'comfortable interface' in some cases, and in other cases I can also use the 'clean', object-orientated interface.

It is just impossible to do something like
t:TGraphics = TGraphics.create(width, height)
t.setAlpha(a)
t.drawOval(x,y,width,height)
t.end()

which would be such a nice thing to do.


H&K(Posted 2006) [#4]
Why is it impossible to do?

YOU could quite easerly extend TGraphics yourself, and make it so.

Though I do agree withyou. If you look at simons minib3d the simple functions are still there even though its all done in types. So if an external function exist, so does a types function
Function Dosomthing(AType, param,param)
AType.DoSomthing (Param,Param)
EndFunction
I have no problem with the function existing outside a type, but it should exist within the type origionaly. (Normaly).

And infact any situation where the object is passed as the only paramater, should really exist as a method of the object type.


tonyg(Posted 2006) [#5]
Before I start... I agree.
Before I finish... sorry for the tirade.
Isn't this just a case of having the source and access to the methods?
If we didn't the only thing you would be able to use is the documented (don't start me on the documentation...)commands (functions).
I quite like the hybrid OOP/Basic monster that Mark's created. What gets my goat is the lack of focus from BRL on what's currently being used. It could (easily) be so much better.
<rant on>
e.g. (again) others have produced Render-to-texture, streaming sound, funky Gui OOP wrappers, additional blend modes, IDE improvements BUT they don't get in the official product.
I had this vision of a constantly evolving/improving product while, to me, it seems that BRL has thrown a juicy bone into the community and said "Do what you will with that but don't bother us we're off to make a 3D module"
Too often it seems good stuff is wasted as the source has to be updated which is gone next syncmods/update. Even the docs we could update ourselves but it gets overwritten next time docmods is run.
I've tried to code things where changing the source would make it easy but, to externalise it, would be too much hassle to bother.
<rant off>


WendellM(Posted 2006) [#6]
Some modules, like the List-module, are completely useable using OO. myList.this, myList.that, you can do it all. However, there are also some global functions, like ListAddLast(). Why is that function in there?

I agree with the comments above that it's for old-skool compatibility. I like situations where both exist, like ListAddLast and the ".AddLast" method, and Len for arrays along with the ".Dimensions" method. That way, if I'm feeling all 1980s, I can use what's in the back of my mind, or I can get all New Age and go with the OO alternative <g>.

I personally make my stuff very OO, so there are lots of TWhatever.Create's and TWhatever.Destroy's (however, I'm lazy, so I just directly access Fields rather than bother with writing tons of .Get's and .Set's - yes, I live on the dangerous edge).

But I get your point. Sometimes I'll be expecting to use an OO approach (especially with MaxGUI) and there isn't one. That's when I go "Why are there separate TextFieldText and TextAreaText functions? Where's the '.Text' method (or '.Caption') that VB has had since forever?" But then I calm down <g>. However, I have been tempted to write my own OO extensions as mentioned above, just for completeness. So I guess what I'm saying is, "I feel your pain." <g> But ours is a happy, quixotic Basic, so I happily muddle through.


Chris C(Posted 2006) [#7]
I have to agree with tong, I've given up with bug reports / module tweaks, whats the point? theres been some really good stuff simply ignored, take for example a lost focus for event gadgets handed on a plate to brl with solutions for all 3 OS's
The guy who worked on these worked *very* hard to get this most useful feature working, with no feedback on the forums from brl who knows if this very useful tweak will be included?

and as for design? well max obviously has been designed on the fly, and in places it really shows

having said that aside from brl's basic lack of manners, max despite brl is quite a good language, just terribly supported.

ahh spleen vented... ;)


Punksmurf(Posted 2006) [#8]
Of course I can extend TGraphics, but unless I want it to get lost with the next update I'd have to make a new type which extends the original type. Due to the setup of the Max2D lib it's just more than just getting it wrapped up, as far as I can see. Then again, I find it should be possible by default.

I must admit that at some point I lack the skill to completely understand it all, but I'll try ;) to figure out something nice around the graphics object this afternoon (as that is the main thing I'm having problems with). Anyway, spitting trough the source will level up my skills so there's nothing wrong with that.

The global functions still bother me. As I'm currently having some trouble with SetAlpha, I'll give an example...

I know, this is quick and dirty (and not the way I'd like to do it, but for simplicity's sake...)

Graphics (640 , 480 , 0 , 0 , 0)

Type TTest
	Method SetAlpha(a:Float)
		Print a
	End Method
	
	Method draw()
		SetAlpha(0.5)
		DrawOval (10 , 10 , 100 , 100)
		Flip
	End Method
End Type

t:TTest = New TTest
t.draw()

While Not KeyDown(27); Wend


What I want to do here, is to draw a 50% opaque circle. But since I also have a method named 'setAlpha', the draw-routine will call the method setAlpha (as it should, of course) but not the global function, which, at the moment, is the only way of setting the alpha. So, if you have an object with a method which has the same name as a global function, you cannot call this global function from your object.

Of course you'll tell me that I shouldn't have methods and global functions using the same name, and damn well you're right. But there shouldn't be all those global functions at all.

I understand that they are easy and nice for those new to max, and that it's still basic, but wouldn't it be nice if we just could use the Framework/Import commands to not include several modules containg those global functions?


H&K(Posted 2006) [#9]
Surly it would only get overwritten is you actualy changed TGraphics. I wasnt sudjesting that, I was saying extend it, in the sence of your "I'd have to make a new type which extends the original type.", statement.
Type TPunksTGraphics Extends Tgraphics

    Field FAlphaLevel:Int

    Method SetAlpha(PAlphaLevel)

        Self.FAlphaLevel=PAlphaLevel
        SetAlpha (Self.FAlphaLevel)       ' If SetAlpha is namespace global. or
        Super.SetAlpha (Self.FAlphaLevel) ' If SetAlpha is Tgraphics Namespaced

    End Method

    Method Draw ()

        SetAlpha Self.FAlphaLevel
        ..
        ..
    End Method

Endtype

MyGraphics:TPunksTGraphics = New TPunksTGraphics

MyGraphics.Setalpha (24)
MyGraphics.Draw ()
And anything that wants a TGraphics, can be passed a TPunksTGraphics, because a TPunksTGraphics is a TGraphics


ziggy(Posted 2006) [#10]
Take in consideration that BlitzMax was designed for OO programming, and for procedural programming, so most of the methods defined in types, are also available as functions. this is not bad design. there are some little issues with OO design, but those are being improved in new BlitzMax versions (as instance, the TGraphics object was not available in older BlitzMax versions).


ziggy(Posted 2006) [#11]
@Punksmurf:
In a framework oriented development environment, it's a good practicle to write the full path of functions when there are functions with the same name.

Graphics (640 , 480 , 0 , 0 , 0)

Type TTest
	Method SetAlpha(a:Float)
		Print a
	End Method
	
	Method draw()
		brl.max2d.SetAlpha(0.5)
		DrawOval (10 , 10 , 100 , 100)
		Flip
	End Method
End Type

t:TTest = New TTest
t.draw()

While Not KeyDown(27); Wend



dmaz(Posted 2006) [#12]
ziggy is right with

brl.max2d.SetAlpha(0.5)

but if you don't want to bother to look it up you can shortcut it in your methods with

.SetAlpha(0.5)


Punksmurf(Posted 2006) [#13]
Hey ziggy, that's cool. I didn't know that that was possible. Thanks!

That graphics thing I was trying lately turned out to be harder than I thought, but I'll continue fiddling with it.

However, I'll be off to France on vacation the next two or maybe three weeks, so no updates on that matter. I take my computer with me, but the whole internet's a bit too large for my trunk ;)