blitz-foundation / monkey2

zlib License
3 stars 0 forks source link

Feature Request : 'With' statement #80

Open Pharmhaus-2 opened 5 years ago

Pharmhaus-2 commented 5 years ago

Original Author: arpie42

Like in Pascal, or Javascript, or D...

Code like this seems so unnecessarily verbose :

...
canvas.Scissor=New Recti( sx,sy,sx+sw,sy+sh )
canvas.Clear( New Color( 1,32.0/255.0,0,1 ) )   
canvas.PushMatrix()
canvas.Translate( tx,ty )
canvas.Scale( Width/640.0,Height/480.0 )
canvas.Translate( 320,240 )
canvas.Rotate( Millisecs()*.0003 )
canvas.Translate( -320,-240 )
...

Isn't this so much cleaner :

...
With canvas
 .Scissor=New Recti( sx,sy,sx+sw,sy+sh )
 .Clear( New Color( 1,32.0/255.0,0,1 ) )    
 .PushMatrix()
 .Translate( tx,ty )
 .Scale( Width/640.0,Height/480.0 )
 .Translate( 320,240 )
 .Rotate( Millisecs()*.0003 )
 .Translate( -320,-240 )
End WIth

The above is a fairly trivial example to simply avoid some typing but it can be oh so much more powerful :

With SlowComplexFunctionToLookupAnObject()
 .DoThing()
 .DoOtherThing()
 ... do lots of things with the object you looked up, without having to create a local variable to hold it
End With

Or :

With New ThingThatNeedsComplexInitialisation()
 .BuildFoundations()
 .AddRoom("Home", 2, 2)
 .AddDoor(2,2,2,3)
 .AddCorridor(5,5,5)
 ...build whole house, or whatever
End With