Is use of GOSUB bad coding?

Everything else that doesn't fall into one of the other PB categories.
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

Dioxin wrote:
I'm only able to speculate as I don't actually own PureBASIC...
Paul... Dioxin.... Assembler... hmmmm! Sounds a lot like Paul Dixion on the PowerBASIC forum.

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
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

blueb wrote: snip.

Paul, this is the best $60 I ever spent. Great compiler, great forum with lots of sample code... simply the best!

--blueb
ditto.

cheers
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

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)
( The path to enlightenment and the PureBasic Survival Guide right here... )
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

It shouldnt screw up anything.

(if fred increases eg AX every loop or whatever to count, it will hopefully be reset before next loop.)
dioxin
User
User
Posts: 97
Joined: Thu May 11, 2006 9:53 pm

Post by dioxin »

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:
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.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

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,
Last edited by rsts on Wed May 17, 2006 9:15 pm, edited 1 time in total.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

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.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

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:

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()
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!
akee
Enthusiast
Enthusiast
Posts: 496
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Post by akee »

If you need to GO to a SUB, then make sure you return... :)
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

An example, pretty please :)
thefool wrote: I've even made examples where they wouldnt find the code and so on.
Post Reply