|
Post by Rod on Nov 28, 2022 4:48:23 GMT -5
TRACE,n what? how? when? Hands up if you have ever used it!
|
|
|
Post by xxgeek on Nov 30, 2022 15:03:14 GMT -5
Puts hand up.
Trace comes in handy when debugging. From JB Help: There are three trace levels: 0, 1, and 2. Here are the effects of these levels:
0 = full speed no trace or RUN 1 = animated trace or ANIMATE, logs variables and highlights current line 2 = single step mode or STEP, requires programmer to click STEP button to continue to next line of code to execute, logs variables -end of jb help
To use trace, just add it to your code where there is a problem, then use debugger to step through your code step by step, or animate. Here is a small example of code with a problem (2 problems, but the coder thinks he's got everything right);
eg:
nomainwin if VAL(Version$)<2 then notice "Just BASIC 2.0 required" end end if if fileExists(StartupDir$, "jbasic2.exe")=0 then notice "Please, run this bas file or tkn from ";_ "the Just BASIC IDE (launch it from the desktop or the start menu)" end end if
When run, this will not get by the debugger. Error message "Basic Compile Halted: Type Mismatch. array fileExists() requires numeric parameters" will appear at the bottom of the JB IDE window, and the line "if fileExists(StartupDir$, "jbasic2.exe")=0 then" will be highlighted.
trace won't help here since the debugger won't open for the user with this type of error, or syntax errors, or for without next errors, while without wend errors etc. But the programmer will see that line highlighted and know right away that "oops, I forgot to add the fileExists function."
After adding the fileExists function, the programmer runs the code again only to find out there is another problem when he gets the notice "Please, run this bas file or tkn from the Just BASIC IDE (launch it from the desktop or the start menu)", and the program abruptly shuts down after acknowledging/closing the notice.
This type of error will allow the programmer to take advantage of trace to find the problem, since the debugger will open if/when the programmer clicks the debugger icon. So, we add trace 2 to the code after the first check (for Version$, since we know that code worked, and no notice of "Just BASIC 2.0 required" happened.
nomainwin if VAL(Version$)<2 then notice "Just BASIC 2.0 required" end end if trace 2 if fileExists(StartupDir$, "jbasic2.exe")=0 then notice "Please, run this bas file or tkn from ";_ "the Just BASIC IDE (launch it from the desktop or the start menu)" end end if
Now when the debugger is run, the code stops executiong at the line with trace 2 and waits for the programmer to either step through the code line by line, or animate (or another option, like step over, step out, or resume)
Stepping through the code line by line the programmer will see that the result of fileExists() on jbasic2.exe does in fact show a value of 0. Now the programmer shakes his head, what? That file "should" exist he says to himself. And then promptly opens file explorer and navigates to StartupDir$ manually to visually check if in fact that file has been deleted somehow.
The programmer promptly finds out that "OOPS, got the name wrong." "Was thinking of jbrun2.exe when I wrote jbasic2.exe.jbasic.exe does not have a 2 in the name"
Problem solved. The programmer was an idiot. (won't mention programmers name and embarrass myself)
|
|