SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Brucey's Modules => Topic started by: wadmixfm on August 12, 2020, 11:30:32 AM

Title: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 11:30:32 AM
would it be possible for us novices to have the old commands back ????

goto and the #label commands were great and simple

now you have to write upto 20 more lines of code to get it to do a simple jump to a line.

in machine language they use the Jmp command and no one complains

isnt it down to the end user if we would like these features or not

could you add a switch in the ide to turn it on or off for example

Lee

 :D :D :D :D :D :D
Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 12, 2020, 11:45:03 AM
Cannot think of a single scenario where you would ever need goto/gosub - even less so one that would require a 20-line work-around.

I think you're asking for features that you understand, to stand in for the ones you just haven't learned about yet
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 12:03:06 PM
no i understand it perfectly , but i cant see why two little commands have been taken away
which are not damaging the size of blitzmax source ,i have been working on a few old programs from the vanilla days of blitzmax and its a lot of code to be going through converting the goto's and the labels.

its down to the user if they want to use them or not right ???

so why not leave them in ??

so people that still want to use them can do

you dont go into a shop and buy a pencil and the shop keeper says you cant use that to draw with.

Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 12:05:12 PM
all i want to do is convert my programs to run in 64 bit and doing this i need to use NG i like the look of NG but taking things away is not the way forward for me anyways.

Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 12, 2020, 12:10:33 PM
no i understand it perfectly , but i cant see why two little commands have been taken away
Because they are obsolete.  They simply aren't needed in object-oriented code.

Quote
its down to the user if they want to use them or not right ???
Well, they've been removed.  So, no.

Quote
you dont go into a shop and buy a pencil and the shop keeper says you cant use that to draw with.
But pencils are still pretty much the best option for drawing with.  In fact if you went into a shop and asked for a bundle of twigs and some fire so you could scratch your doodles into a cave wall, a pencil would probably be recommended to you.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 12:21:03 PM
why dont they write a mod for it for user to have if they want it??

another scenario

i have just bought a new car and it had overdrive  , but my car went in for a service and you removed it , but i still want to use it , why did you take it away ???

i paid 80$ for blitzmax and i am not getting the service i paid for
if i want these feature dont i have a right to have them ??

 
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 12:30:36 PM
and explain to me why the goto command is still in the commands list and it still shows the example oh how to use it

i feel the option has been disabled in the compiler (bcc)

just recently learned about this file in the source code
there is a restriction in the compiler code to stop goto correct ??

   stm.cpp
   Removed restriction which didn't allow Goto in strict mode

Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 12:32:01 PM
ok if you cant bring it back is there a 64bit port of blitzmax ???

Title: Re: can we bring back The Goto and #label commands into NG
Post by: Steve Elliott on August 12, 2020, 12:45:42 PM
First of all Blitzmax was abandoned by the author and left open source.  So complaining you're not getting the service you paid for is well, tough.  Mr Mark Sibly walked away from BlitzMax so it no longer exists.  Brucey worked hard to bring a new 64-bit version called BlizMax NG or it would have died completely.

Using the Goto command and jumping about all over the place is bad programming practice in a structured or object oriented language, so I can understand why Brucey removed it.  Mark made the mistake of allowing all sorts programming styles to mix, and with all that strict, super strict nonsense too.  So people like yourself can quite rightly feel annoyed because the original author allowed everybody to do whatever they want, rather than being sensible and putting in a standard syntax for everybody to follow.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 01:05:00 PM
so again for us novices that dont do this kind of thing day in day out

whats the alternative to goto and labels

my old programs work fine in 32 bit mode no lag or slow down no memory leaks and i can also when it came too debugging errors could always find where i had gone wrong,but i want to update it into the 64 bit market and to migrate onto other platforms like mac os catalina which i know is 64bit also.

typical scenario -

local me
for i = 1 to 1000
if i = 500 then me = 500 then goto me2
next

...... loads more code here say another 1000 lines

#me2
end

i know about functions but you are tied to them as its

function me()
..... do something

end function

then call it

but i have a lot of loops and jump arounds to do

 
Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 12, 2020, 02:08:40 PM
Quote
i paid 80$ for blitzmax and i am not getting the service i paid for
It's been open-source (and free) for ages now.  So if you paid $80 for it, you must have had it at least six years.  And BlitzMax still works today so nothing has been taken from you, as you seem to be suggesting.

Further, BlitzMaxNG is nothing at all to do with the original creator of BlitzMax.  Brucey (to my knowledge) has not charged anyone a cent for the work he's done on the NG version since.

Bottom line, if you want to use Goto, stick with the last official release of BlitzMax.  That is, after all, what you paid for.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 02:25:37 PM
very positive gfk

all i want to know is can i compile my code in 64bit with ease

seems i have to take 20 turns just to execute a simple 2 step operation

i dont want to be rewriting all my code again and yet i want to upgrade to NG and 64bit

is there any solutions apart from the obvious??

Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 12, 2020, 03:17:38 PM
very positive gfk

all i want to know is can i compile my code in 64bit with ease

seems i have to take 20 turns just to execute a simple 2 step operation

i dont want to be rewriting all my code again and yet i want to upgrade to NG and 64bit

is there any solutions apart from the obvious??
No.  Rewrite your code.  If it's that badly written in the first place that Gotos are required, then a complete rethink should be top of your 'to do' list.


Quote
typical scenario -

local me
for i = 1 to 1000
if i = 500 then me = 500 then goto me2
next

...... loads more code here say another 1000 lines

#me2
end

i know about functions but you are tied to them as its

function me()
..... do something

end function

then call it

but i have a lot of loops and jump arounds to do
Your 'typical scenario' doesn't even make sense.  You have two "then"s on the same line - is that even legal syntax in Blitzmax?  Also you're just ditching the entire loop when you reach 500 anyway, so why set it up for 1,000 iterations?

And to be honest I just gave up trying to comprehend it when you complained that you're "tied to functions".  If you're even avoiding the use of functions, then coding probably isn't for you.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 12, 2020, 04:02:37 PM
the program i have written in blitzmax works fine

with no errors in 8551 lines of code and no one can help me with a goto alternative

thanks



 
Title: Re: can we bring back The Goto and #label commands into NG
Post by: TomToad on August 12, 2020, 04:14:56 PM
I am assuming your scenario is a standin for a more complex function, like searching through an array.

One way to do it would be to set me to a default value representing "value not found" and then testing for that value after exiting the loop.  In my example here, I default to -1.
Code: BlitzMax
  1. Local a:Int[] = [1,3,5,7,9]
  2.  
  3. For Local valueToSearch:Int = 1 To 10
  4.         Local me:Int = -1
  5.  
  6.         For Local i:Int = 0 Until a.length
  7.                 If a[i] = valueToSearch
  8.                         me = i
  9.                         Exit
  10.                 EndIf
  11.         Next
  12.  
  13.         If me < 0
  14.                 Print valueToSearch+" was not found"
  15.         Else
  16.                 Print valueToSearch+" was found at index "+me
  17.         EndIf
  18. Next
  19.  

Another way would be to use loop labels with exit and wrap your function in a Repeat/Until block.

Code: BlitzMax
  1. Local a:Int[] = [1,3,5,7,9]
  2.  
  3. For Local valueToSearch:Int = 1 To 10
  4.         Local me:Int = -1
  5.  
  6. #looplabel
  7.         Repeat
  8.                 For Local i:Int = 0 Until a.length
  9.                         If a[i] = valueToSearch
  10.                                 me = i
  11.                                 Exit looplabel
  12.                         EndIf
  13.                 Next
  14.                 Print valueToSearch+" was not found"
  15.         Until True
  16.         If me >= 0
  17.                 Print valueToSearch+" was found at index "+me
  18.         EndIf
  19. Next
  20.  

Of the two, I prefer the first version as it is more clear as to what you are trying to do.

Better than either would be to put the routine in its own function.
Code: BlitzMax
  1. Local a:Int[] = [1,3,5,7,9]
  2.  
  3. For Local valueToSearch:Int = 1 To 10
  4.         Local me:Int = getArrayIndex(a, valueToSearch)
  5.         If me < 0
  6.                 Print valueToSearch+" was not found"
  7.         Else
  8.                 Print valueToSearch+" was found at index "+me
  9.         EndIf
  10. Next
  11.  
  12. Function getArrayIndex:Int(a:Int[], valueToSearch:Int)
  13.         For Local i:Int = 0 Until a.length
  14.                 If a[i] = valueToSearch Then Return i
  15.         Next
  16.         Return -1
  17. End Function
  18.  
This way, the routine can be used multiple times throughout your program, with different arrays and different values, without having to rewrite the same routine over again.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: Qube on August 12, 2020, 04:27:45 PM
the program i have written in blitzmax works fine

with no errors in 8551 lines of code and no one can help me with a goto alternative

thanks
You will have to ditch goto and instead think of functions as your goto label.

I do not know what me = 500 is about ( or your code, lol ) but...

So something on the lines of :

Code: BlitzMax
  1. local me
  2. for i = 1 to 1000
  3.         if i = 500
  4.                 me = 500
  5.                 me2( 500 )
  6.         endif
  7.         if i = 750
  8.                 me = 750
  9.                 me2( 750 )
  10.         endif
  11. next
  12.  
  13. ' loads more code here say another 1000 lines
  14.  
  15. ' nothing below this line will run except when called
  16.  
  17. function me2( value )
  18.         if value = 500
  19.                 ' do funky stuff
  20.         endif
  21.         if value = 750
  22.                 ' do funky stuff followed by
  23.                 me3()
  24.         endif
  25. end function
  26.  
  27. function me3()
  28.         ' do more funky stuff
  29. end function
  30.  
Title: Re: can we bring back The Goto and #label commands into NG
Post by: MikeHart on August 12, 2020, 06:59:23 PM
If i understood Blitzmax and NG correctly, the original created assembler where you could support Goto essily as a compiler. NG on the other hand translates to C++ which gets compiled by a Compiler. and there Goto and Gosub doesn't exist.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: Henri on August 12, 2020, 09:53:16 PM
NG produces C code and goto is possible in C as far as I know (although all the people using it in higher level languages are looked down upon :-)).

Another matter is that goto is a legacy feature of basic to begin with and was only supported in non-strict mode or the 'hippie mode' in the original Blitzmax and ng is strict by default. I would give it a snowballs chance to ever surface in ng...

The good news is that it is not really needed. Every possible scenario can be done without it. And, I bet you don't even have to write 10 times more code to achieve the same. At the end you might even develop a different way of structuring your code, evolve as a programmer. At least I did..
 
 Anyways, good luck.

-Henri
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 13, 2020, 12:33:37 PM
thanks for the great replies

so here is what i am looking for

for example :-

repeat

If KeyHit(KEY_1) Then goto drumplay
If KeyHit(KEY_2) Then goto kited
If KeyHit(KEY_3) Then goto loadnsave
If KeyHit(KEY_4) Then goto quit

until


#drumplay

..... code here


#kited

........ code here


#loadnsave

........ code here



#quit

end program code here

if there is an alternative to this then i will be very happy

lee

sorry to cause issues


ps the me was a variable

if i = 500 then me = 500

lee

its not part of my original code i just threw that in




Title: Re: can we bring back The Goto and #label commands into NG
Post by: Steve Elliott on August 13, 2020, 12:39:39 PM
Just replace labels with functions:

Code: [Select]

If KeyHit(KEY_1) Then drumplay()

...

function drumplay()

... code here

end function

Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 13, 2020, 12:46:04 PM
yeah i tried that

can you call another place from that function ???

can you add a function in a function ??

Title: Re: can we bring back The Goto and #label commands into NG
Post by: Steve Elliott on August 13, 2020, 12:50:42 PM
Quote
yeah i tried that

can you call another place from that function ???

can you add a function in a function ??

You tried that and what?  It didn't work??  It should.

Yes, you can call other functions from a function.

Why would you add a function to a function??  Just call several functions from a function if you want.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 13, 2020, 12:57:19 PM
tried the code you sent

when calling a function do you address it as

program()

or just

program

for example

Title: Re: can we bring back The Goto and #label commands into NG
Post by: Steve Elliott on August 13, 2020, 01:06:25 PM
You would use program() because you pass in data through variables within the brackets.  No data is required if you're just emulating a label therefore just use ().  But if you wanted to send say, x and y values to a function you could use program( x, y ).  Now BlitzMax needs to know what kind of data type it is, so when you define a function with integer (whole numbers) as an example you would say:

Code: [Select]
x = 10
y = 20

program( x, y )

...

Function program( x:Int, y:Int )

... process x and y here

End Function


Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 13, 2020, 01:27:35 PM
' how is this , it works but is this the right way to do it :)
'new specdrum 2
Import BaH.RtMidi
Import BRL.StandardIO
Import brl.D3D9Max2D
Import brl.Max2D
Import BRL.Retro
Import BRL.Random
Import BRL.Math
Import BRL.LinkedList
Import MaxGui.Drivers
Const GFX_WIDTH = 1024, GFX_HEIGHT = 768, BIT_DEPTH = 0, HERTZ = 75
AppTitle ="SpecDrum2 64bit Version "
'Center the screen on startup
SetGraphicsDriver GLMax2DDriver()
Graphics GFX_WIDTH, GFX_HEIGHT, BIT_DEPTH, HERTZ


Function begin()
Local hiya
hiya=0

Repeat
Cls

DrawText"Press 1 or 2 or 3 to quit",20,40
If KeyHit(KEY_1) Then test1
If KeyHit(KEY_2) Then test2
If KeyHit(KEY_3) Then End
Flip
Until hiya=1
End Function


Function test1()
Cls
DrawText "you have reached test 1",60,60
Flip
Delay 1500
begin()
End Function


Function test2()
Cls
DrawText "you have reached test 2",60,60
Flip
Delay 1500
begin()
End Function

begin()  ' this is the main call of the functions
Title: Re: can we bring back The Goto and #label commands into NG
Post by: Steve Elliott on August 13, 2020, 02:19:07 PM
Well it works is a good thing!   :D

I would re-write it a bit differently, but it works is the main thing.  Maybe somebody will jump in here as I don't have time right now.
Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 13, 2020, 03:20:04 PM
That code 'as-is' would eventually cause a stack overflow, since you're repeatedly calling your begin() function, which calls test1()/test2(), which both call the begin() function, which calls test1()/test2() and so on ad infinitum.  Fair do's, in the scale of things it would take a long time for that to happen, but an ever-growing stack trace is never good.

Losing the calls to begin() from within test1() and test2() will fix that - it's not needed, since code execution will return to where it left off in the begin() function anyway, once test1/2 have completed (at which point they're removed from the stack buffer).
Title: Re: can we bring back The Goto and #label commands into NG
Post by: wadmixfm on August 13, 2020, 03:23:32 PM
ahhhhhh i see

so once its called and ended it will have to be called again if i want to go back to that part of code

right ?

Title: Re: can we bring back The Goto and #label commands into NG
Post by: GfK on August 13, 2020, 03:47:40 PM
Right.

Every time you call a function, your code has to "remember" where it was called from, so it can return to it later.  Once the function has finished executing, code execution goes back to that point and it "forgets" the thing it remembered as it's not needed any more.  In laymen's terms, that's what the stack buffer does.

In your code, neither of your test functions were ever completed (by reaching the end of the function), since you were calling the begin() function before that happened.  As a result the stack buffer would just keep growing and growing, filling up with pointers to begin(), test1/2(), begin(), test1/2() and so on.

Not sure if BlitzMax has any way of looking at the stack trace.  If it does, I don't remember it.  But (having used Unity for years now) it's a handy thing to have access to as you can see the exact path your code has taken to get to where it is.  It's super-useful in debugging.

Title: Re: can we bring back The Goto and #label commands into NG
Post by: TomToad on August 13, 2020, 05:11:11 PM
There is a stack trace of sorts when using the debugger.  As you step through a program, line by line, the function call stack will be in the "debug" tab on the right.
SimplePortal 2.3.6 © 2008-2014, SimplePortal