Is use of GOSUB bad coding?
Dare2,
well of course you'd put the GOSUBs beyond the END so as not to need the jump. I only did it the way I did so it was directly comparable to the "pretty" Procedure version and would hopefully take on some of the pretty characteristics of that version, at least in the eye of its creator.
The "less typing" comment wasn't meant to be taken too seriously, after all, if you call the GOSUB many times it takes 3 characters more typing each time than the PROCEDURE version so in real life it'll take more typing.. but don't tell the others or they'll use it to argue against GOSUBs!
As for the timing of GOSUB vs. PROCEDURE, I'm only able to speculate as I don't actually own PureBASIC so I can't compile or experiment with it but, as a guess, I'd say that the routines are both very short and in very tight loops so will be prone to the well known branch target alignment problem. If the code was moved around a bit, for example by swapping the position of the PROCEDURE and GOTO calling routines, or by adding a small amount of code at the start of the program, then it may give different results.
Sounds like atom spiltting again, I know, but you can gain or lose 20% in speed by altering the alignment of critical parts of your code.
Paul.
well of course you'd put the GOSUBs beyond the END so as not to need the jump. I only did it the way I did so it was directly comparable to the "pretty" Procedure version and would hopefully take on some of the pretty characteristics of that version, at least in the eye of its creator.
The "less typing" comment wasn't meant to be taken too seriously, after all, if you call the GOSUB many times it takes 3 characters more typing each time than the PROCEDURE version so in real life it'll take more typing.. but don't tell the others or they'll use it to argue against GOSUBs!
As for the timing of GOSUB vs. PROCEDURE, I'm only able to speculate as I don't actually own PureBASIC so I can't compile or experiment with it but, as a guess, I'd say that the routines are both very short and in very tight loops so will be prone to the well known branch target alignment problem. If the code was moved around a bit, for example by swapping the position of the PROCEDURE and GOTO calling routines, or by adding a small amount of code at the start of the program, then it may give different results.
Sounds like atom spiltting again, I know, but you can gain or lose 20% in speed by altering the alignment of critical parts of your code.
Paul.
Dioxin wrote:
Paul, this is the best $60 I ever spent. Great compiler, great forum with lots of sample code... simply the best!
--blueb
Paul... Dioxin.... Assembler... hmmmm! Sounds a lot like Paul Dixion on the PowerBASIC forum.I'm only able to speculate as I don't actually own PureBASIC...
Paul, this is the best $60 I ever spent. Great compiler, great forum with lots of sample code... simply the best!
--blueb
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
are you simply allowed to jump out of loops with a goto, will it not screw up anything internally in pb?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Blueb,
that'll be my evil twin brother. We try not to talk about him, he's nothing but trouble.
$60? It now says this on the ordering page:
blueznl,
if a compiler is written properly there should never be a problem jumping OUT of a structure provided you remain in the same procedure.
Jumping into structures or into/out of procedures is a different matter.
Paul.
that'll be my evil twin brother. We try not to talk about him, he's nothing but trouble.
$60? It now says this on the ordering page:
PureBasic Price
Country Cost per copy
All US$ 99
blueznl,
if a compiler is written properly there should never be a problem jumping OUT of a structure provided you remain in the same procedure.
Jumping into structures or into/out of procedures is a different matter.
Paul.
Hmm - must have raised the price with V4.
Still the best bargain around - especially with a lifetime license.
Get in now before the V5 price increase
cheers,
Still the best bargain around - especially with a lifetime license.
Get in now before the V5 price increase
cheers,
Last edited by rsts on Wed May 17, 2006 9:15 pm, edited 1 time in total.
Maybe v5 will have 'Procedure' replaced by GOTO ? 
My original question wasn't intended to spark such a debate but i'm glad it did now. This whole conversation has gotten me really interested in exploring the most usable and flexable way of streamlining code as much as possible in a 'modular non-linear' fashion (i use 'modular' for lack of a better word right now) instead of a linear fashion.
My original question wasn't intended to spark such a debate but i'm glad it did now. This whole conversation has gotten me really interested in exploring the most usable and flexable way of streamlining code as much as possible in a 'modular non-linear' fashion (i use 'modular' for lack of a better word right now) instead of a linear fashion.
If you want modulear non linear code, go OOP 
(in purebasic if you want to. or praise fred to build some basic class support in. Perhaps he will listen one day
)
Or use goto's a lot.
You can also use gosub and return as a simple procedure. I guess it has slightly less memory overhead and is a little faster... (for optimizer freaks.. but perhaps im not right.)
procedures got some other advantages but if you REALLY are an optimizing freak i would wonder if using GOTO's or gosub/return would work...
perhaps someone can test it?
goto example:
edit: just thought i would say this; The use of using RET to jump to code positions can annoy some disassemblers. wich is good 
I've even made examples where they wouldnt find the code and so on. Also, the crackers don't know the place to jump sometimes
How? Because you can push like you want to. You can push anywhere, just as long as you don't change the stack. You can use it in an if loop.
if serial="blah"
push ?goodlocation
else
push ?badlocation
endif
;perhaps do something. jump somewhere, then perform a RET!
(in purebasic if you want to. or praise fred to build some basic class support in. Perhaps he will listen one day
Or use goto's a lot.
You can also use gosub and return as a simple procedure. I guess it has slightly less memory overhead and is a little faster... (for optimizer freaks.. but perhaps im not right.)
procedures got some other advantages but if you REALLY are an optimizing freak i would wonder if using GOTO's or gosub/return would work...
perhaps someone can test it?
goto example:
Code: Select all
;jump the code over.!
Goto main
;********************************
;"function" one.. using goto and RET
ShowAbout:
MessageRequester("About!","This little example is programmed by me!")
RET ;RET will now jump back to the address last stored in the stack!
;********************************
;********************************
;"function" two. using gosub
PrintThing:
PrintN("Now im in my gosub!")
Return ;Return.
;********************************
main:
;main code:
OpenConsole()
;Calling function one and returning..
PrintN("Going to show about using goto's and gosubs.")
PUSH l_back ;Pushing the address of the label back into the stack.
Goto showabout
back:
PrintN("Now im back!")
Input()
PrintN("Running into my second function!")
Gosub printthing ;Perhaps this is just pushing a hidden label to the stack like above code?
PrintN("back!")
Input()I've even made examples where they wouldnt find the code and so on. Also, the crackers don't know the place to jump sometimes
How? Because you can push like you want to. You can push anywhere, just as long as you don't change the stack. You can use it in an if loop.
if serial="blah"
push ?goodlocation
else
push ?badlocation
endif
;perhaps do something. jump somewhere, then perform a RET!




