Qbasicnews.com
December 16, 2019, 10:09:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3 4 ... 11
  Print  
Author Topic: Structured Programming  (Read 31796 times)
GordonSweet
Guru
**
Posts: 287



WWW
« Reply #15 on: December 07, 2005, 04:51:45 AM »

As I understand it the main principle behind Structured Programming is avoiding the use of GOTO and GOSUB, apart from of course such as sensibly making sure your DIMs are at a the start and DATAs at the end. It also helps to try to use descriptive names to Variables and strings. Unfortunately this all make extra work, long names for variables may even slow up the program.

Avoiding the use of GOTO and GOSUB is fairly easy with BBCBASIC as it boasts the option of PROCedures. Liberty basic has no such luxuries and needs the constant use of these, though like QB any essential line numbers can be replaced by descriptive [labels]. However there is if course a much wider use of LB ( especially on the US).

BBCBASIC accepts only line numbers. There are several hundred examples of both languages on my site.  Most of those in the BBCBASIC for Windows were published on a UK magazine the Beebug in the 80s and have now been released from copyright, and which I am continually adding. You may find some of interest for converting to QB and FB etc. Though in a ,BBC  format there is a program BBCtoBAS for converting any to a readable ASCII BAS format, all run by activating the BBCMENU.EXE provided in each ZIP.

Gordon

 http://sionet.mysite.wanadoo-members.co.uk/npage4.html
Logged
axipher
Ancient Guru
****
Posts: 544



« Reply #16 on: December 07, 2005, 12:06:53 PM »

most programmers flame the use of goto and gosub, and are always saying that you should use SUB's instead, but sometimes you just got to use goto's to accomplish a task rather then copy and re-paste the need code over and over again
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #17 on: December 07, 2005, 12:16:56 PM »

GOTO can always be substituted by a structured block. Most of the time, it's better not to use it 'cause you get a more readable code, specially if you are working with someone else. It's just good practice.

Sometimes, a GOTO comes handy to do an optimization, but if you are placing it as a patch you better revise your code. This is just an advice: it's better to rework an algorithm than patching it - spaghetti is easy to produce and can be hard to debug.

GOSUB is an absolute no-no. It doesn't have ANY advantages over structured SUBs or FUNCTIONs. Absolutely none. Why using a messy solution when you have a clean one, which also allows more stuff to be done?

I've always said that GOTO is great if you know what you are doing. Seriously, don't take this as a leet discuss, 'cause it isn't. It's just me giving advice. I've been coding for ages, and I've had to fight with a 200 lines-long spaghetti function just to find that I missed a very simple detail. If I would have had the function correctly structured, just a few watches would have made it to discover the bug.

So Aga wrote it perfectly some time ago: GOTO is like chocolate :lol:
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
GordonSweet
Guru
**
Posts: 287



WWW
« Reply #18 on: December 07, 2005, 01:01:09 PM »

Thanks for all your advice guys.

Gordon
Logged
yetifoot
Ancient Guru
****
Posts: 575



« Reply #19 on: December 07, 2005, 03:48:33 PM »

Quote
GOTO can always be substituted by a structured block


im not sure its strictly true how about nested do's and wanting to exit them all. i know you could set a flag to kick out of each DO in turn but i prefer this style.

Code:
Do
  Do
    Do
      goto pimp
    Loop
  Loop
Loop

pimp:
Logged

EVEN MEN OF STEEL RUST.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #20 on: December 07, 2005, 03:50:35 PM »

Quote from: "na_th_an"
Sometimes, a GOTO comes handy to do an optimization


Wink

In other words, you can always find an structured solution, but sometimes GOTO is faster.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Frenkel
Member
*
Posts: 26



WWW
« Reply #21 on: December 07, 2005, 05:54:08 PM »

Quote from: "GordonSweet"
long names for variables may even slow up the program.


Please explain, I don't understand.
Logged

roeten van Frenkel
Visit us at The Official S&F PROD. Homepage
axipher
Ancient Guru
****
Posts: 544



« Reply #22 on: December 07, 2005, 07:54:57 PM »

longer varibles means more chars in the porogram making it slightly bigger, and longer variable names lengthens the seach of the program if u have variables with similar names, wat ive done in the past is at the and of production, i use the change function in qb to change all variales to a - z using appropriate symbols, and if more are required, then i use aa - zz, etc.  and the goto thing can help, like wat if u want to exit a sub(s) without completeing it, and exit the loop(s) without using an extra variable called like exitloop or something like that
Logged
yetifoot
Ancient Guru
****
Posts: 575



« Reply #23 on: December 07, 2005, 08:02:35 PM »

i was under the impression that varnames are changed during compilation to adresss therefore all varnames will be essentially the same size on compilation.  I could be wrong though
Logged

EVEN MEN OF STEEL RUST.
axipher
Ancient Guru
****
Posts: 544



« Reply #24 on: December 07, 2005, 08:07:02 PM »

be rite though, i nvr decomplied a qb program to see if it does change the variables to adresses along with removing comments ot remarks
Logged
GordonSweet
Guru
**
Posts: 287



WWW
« Reply #25 on: December 08, 2005, 04:29:21 AM »

The way I solved the problem a long time ago of using text book style of long descriptive names for variables etc is to compromise by using short abbrevaited descriptions. Alternatively list very short variables along with their full descriptions at the start of the program

Gordon
Logged
Frenkel
Member
*
Posts: 26



WWW
« Reply #26 on: December 08, 2005, 07:20:29 AM »

Axipher, have you tried compiling a program before and after you changed all the names of the variables and see if the resulting exes were different? My guess is that the exes are exactly the same, or you made a mistake while changing the names.
Logged

roeten van Frenkel
Visit us at The Official S&F PROD. Homepage
axipher
Ancient Guru
****
Posts: 544



« Reply #27 on: December 08, 2005, 11:02:52 AM »

i have tried yes and it does make a slight speed diference, of course my programs were small so bigger programs may be slightly different, its not really that much though, the most it affects for me is getting keyboard and mouse input, other then that it works pretty much the same
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #28 on: December 08, 2005, 12:29:59 PM »

Quote

long names for variables may even slow up the program


Slow......up?  :lol:

I think in general this is not just about GOTO but about having to "structure" every single line as much as possible, and this would often include unnecessary TYPE-like structures.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
marzecTM
Ancient Guru
****
Posts: 688


« Reply #29 on: December 08, 2005, 12:38:20 PM »

aga, what was the biggest application you ever wrote and how long was the maintenance phase after you finished the application?
Logged

quote="NecrosIhsan"]

[/quote]
Pages: 1 [2] 3 4 ... 11
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!