TIPS In a short program you may be able to get away with haphazard organization, but as a program becomes longer it becomes increasingly more important to be organized in your approach. It is a good idea to plan the order that you put things in your program. Some languages have an initialization routine. In this certain variables may be assigned values etc. In AMIGAbasic you can have your own informal initialization routine. There are certain statements which are useful to put at the beginning at a program. These include DIM,OPTION BASE,FRE(If you are watching memory usage) DEFINT and other define statements. It is convenient(but not essential) to put subprograms and subroutines at the end of the program. ORDER OF STATEMENTS It is important to make sure that everything is in the right order. MINIMIZING CODE There are a number of methods which can be used to help keep code concise. SUBSTITUTIONS PLACING CODE ON ONE LINE e.g. instead of x1=asc(x$) x2$=chr$(x1) y=val(x2$) you could write y=val(chr$(asc(x$))) USING SEVERAL STATEMENTS ON ONE LINE Some programmers prefer to have their code fairly well spaced out, others prefer it to be more compact. This is a question of style. A well spaced program may be easier to read. A more compact program can be scrolled through more quickly, and can give the programmer a greater feel of the whole of the program. To make code more compact you can place several statements on the same line by using colons. This can sometimes make a program more difficult to follow, but if the statements are related then they can sometimes make the program even easier to follow. e.g. x1=2:x2=4:x3=7 or cls:paint(1,1),1:color 2,1 INDENTATIONS One option is to use indentations in your programs ans is particuarly useful for matching up the start and ends of nested loops. This can help prevent the ends of loops getting confused e.g. e.g. for a=1 to 5 for b=1 to 5 if c>10 then z=3 elseif c>5 then end if next next SELF DOCUMENTATION It will make things much easier in the long term if you make the program source code as easy to understand as possible. This is especially true if it is to be read by other people. You will be surprised by how much you will have forgotten in 6 months. Here are some awys in which a program can be self documentaing. USE OF COMMENTS Comments can be added to explain what the program is doing at a particular point. This can slow down execution speed slightly, however. One option is to retain comments while a program is being developed and remove them in the final version of the program. MEANINGFUL NAMES Instead of using label and variable names such as zx3 or a5 you can use names which give meaning. A label could describe what the program does at this point. A Variable name could describe what the variable represents. Examples of meaningful names for labels are readtext: addtotals: drawpic: and for variables might be total nam$ flag MINIMIZE USE OF GOTOs Use of many GOTO statements can crate a "spaghetti" program, one that can be very difficult to follow. Where possible, replace GOTOs with IF THEN ,ON GOTO,etc. statements. One way is to place subroutines and subprograms at the end of a program. You can create the main loop of the program, which can then be relatively short, and digestible by the human mind. USER FRIENDLINESS User friendliness means how easy it is for the 'user' of the program to use the program, without making the program crash or go wrong in any way. You can make your program `user friendly' in a number of ways. Firstly, it must not crash while it is rounding. This means that it must be able to accept any kind of input from the user. You must also take into account any strange occurrences during execution. Ways that make a program easier to follow include Minmizing text Use of colours Use of graphics Use of windows For some programs it may be useful to add sound Plan the layout of your windows Reduce the amount of work for the user Use mouse control whenever possible Use inkey$ instead of input(whenever input can be reduced to one character) This saves the user having to hit the return key Give feedback Gives quick feedback to responses Above all, make the program interesting Reducing execution time AMIGABASIC can sometimes execute fairly slowly, particuarly when performing calculations. There are some things which can be done to help speed execution. GOTO statements Variables in calculations Surprisingly enough, it is quicker to perform calculations using variables than actual numbers. e.g. x=213x345x656 will take longer to execute than a=213:b=345:c=656 x=a*b*c shortening searches EDITING Make full use of the editing options available. These can greatly reduce the typing you need to do. it may well pay to learn the keyboard shortcuts. Consider using commands like LIST label and DELETE when in direct mode. When these are known, they may be quicker to use than menus etc. If you ue ED or EDIT, it may well pay to memorize all the important commands. USING OTHER PROGRAMS It is possible to copy text from one of your programs to another by using the copy and paste tools. You may copy a block of text, a subroutine or a subprogram. You may choose to join two files, then delete what you do not need. USE OF SUBPROGRAMS Subprograms can be very useful as they can be used in different programs. Because the variables in a subprogram are independent of those in the main program, there is no danger of using duplicate variable or label names. It is possible to build up your own library of subprograms. MAKING NOTES Always have paper and a pen at the ready to be able to make notes. you may want to make notes as you test run a program. USING A PRINTER If you have a printer, you can use it to print out the listing of a program. this allows you to examine the listing at your leisure and to examine the program in its entirety WRITING YOUR OWN PROGRAMS When you load the AMIGABASIC interpreter 2 windows appear on the screen, the basic window and the list window. Commands typed in the basic window are in direct mode while commands typed into the list window are in edit mode. The first are executed immediately while in the latter case they are not executed until the program is run. Nearly all the time commands are written in edit mode,but sometimes it is useful to write them in direct mode. It is good to save your program fairly reguarly, as it will be lost if the system crashes or the power is turned off. The first time you save it a requester will appear asking for a name when it already has a name you can use save rather than save as. ERRORS There are 2 types of computing errors: Logic errors and syntax errors. Logic erors do not prevent your program from running, rather they produce results different than those you expected. In other words, the program did not do what it ws intended to do. Syntax errors prevent the program from running. They are often due to a typing error in which a reserved word,variable name or label was misspelt or due to a simple oversight. DEBUGGING An error is sometimes referred to as a bug and the process of removing bugs from a program can be called debugging. There are different ways in which a program can be debugged. SYNTAX ERRORS A syntax error happens when a statement or combination of statements does not follow the rules of the language. Some examples of syntax errors are: A mispelt reserved word A reserved word is present without a corresponding word(or words) that should be present with it. Brackets do not correspond. Punctuation such as commas, full-stops,semi-colons are missing or present when they should not be Sometimes they can be due to lack of familiarity with the conventions of the languages. Some syntax errors are detected while the program is loading, others are detected when the program is running. You will know when you get a syntax error, there will be a loud beep and an error message will appear at the top of the screen. Next to the error message will be a box in which you will need to click with the left mouse button in order to click. This will remove the error mesage. The line in which the error appears will be highlighted in red. You can remove this highlighted section by clicking anywhere within it or just by ignoring it. LOGIC ERRORS A logic error in itself is not enough to prevent a program from running. It simply stops the program from doing what was intended. This may be something very major or may be something quite minor. A the cause of a logic error may be immediately obvious or may be extremely obscure. Some tips for finding causes of logic error Isolate the section of the program the error occurs in One way to do this is by using the TRACE,TRON,STEP etc. options from the pull-down menu, which will allow you to examine your program step by step. Sometimes this can be done by temporarily inserting GOTOs at various points in the program. By a process of elimination you can find the offending piece of code. Sometimes though, the cause will be in a completely different part of the program than you expected! Use PRINT statements to discover the values of variables at key points in the program. You may have to add an input statement after the PRINT statement to give yu time to read the values. Otherwise the program may continue scrolling right past. Sometimes you might need to delay the program with INPUT statements to give you time to read the variables, otherwise they may just scroll right past! Have paper and pen ready. SYNTAX ERRORS Some of the common syntax errors and the reasons for them are listed here 11 DIVISION BY 0 You are not allowed to divide a variable or constant by 0 This a mathematical impossiblity! 10 DUPLICATE DEFINITION You have given the same name to 2(or more) arrays Give the arrays different names, or use the ERASE statement to erase the first array before you dimension the second. DUPLICATE LABEL You cannot give the same name to more than one label BLOCK ELSE/END IF must be first statement on line ELSE/ELSE IF/END IF ELSE must the first statement on a line 26 FOR WITHOUT NEXT 29 WHILE WITHOUT WEND One of the above messages occurs if the initial loop statement does not have the corresponding ending command Either the ending command is not in the program or something has prevented the 2 commands from matching up IF without END IF NEXT without FOR WEND without WHILE The corresponding initial command is missing or cannot be matched up 22 MISSING OPERAND An operand like a calculation sign or a joining command is missing 4 OUT OF DATA You have reached past all data statements while using a read statement 6 OVERFLOW Not enough memory to store the variables 14 OUT OF HEAP SPACE There is not enough memory on the stack to run your program. OUT OF MEMORY There is not enough system memory to run your program DISK FULL There is no space left on the disk to store more information. RETURN WITHOUT GOSUB the program has encountered a return statement without reaching a gosub SUBSCRIPT OUT OF RANGE an array element is being asked for that is out of the range of that array set by the appropriate dim statement e.g. an array is dimensioned with the statement dim totals(3) which creates an array named totals with one dimension and 4 elements i.e.total(0),total(1),total(2),total(3) if total(6) appears as part of a statement then there will be still error message if option base 1 is used then a reference to any subscript with a value of 0 will generate this message SYNTAX ERROR the error will be in the line highlighted eg/ mispelling of a reserved word no spaces between words misuse of full stops, colons, semi-colons commas, brackets etc. TYPE MISMATCH you have tried to interchange a string with a numeric value UNDEFINED ARRAY you have referred to an array which was not created with a dim statement There is a complication here. IF AMIGAbasic discovers an undimensioned array if will automatically dimension a single dimensional array with 10 elements of that name. UNDEFINED LABEL you have tried to branch to a non-existent label e.g. with a goto, gosub of ifetc. statement, sometimes happens because of a mispelling UNDEFINED SUBPROGRAM this usually happens when the colon is left off the end of a label name This will also happen if you type in word(which is not a reserved word) on a line by itself. The interpreter thinks that you are trying to call a subprogram which has not been declared. For a more comphrensive list see the workbench manual.