debugging rebol apps
[1/6] from: rishi::picostar::com at: 16-Sep-2000 18:57
Hi. Since rebol does not have a compiler, I find it a bit more difficult to debug large
rebApps.
Anyone have any debugging tips/strategies? Curious how others debug their scripts...
Rishi
[2/6] from: jelinem1:nationwide at: 18-Sep-2000 8:59
Well, since you asked...
I have a fairly large application, divided into several files (modules). My
traditional approach to debugging when I have no "debugger" is to write a
function which prints its argument only when a global variable is set. This
allows me to print messages about the program's behavior while testing,
then turn off those messages when the program works. For a large app I have
developed this to the following:
In the first file which gets loaded into the REBOL session I define the
following flags:
testing: make object! [
all: false
adv: false
item: false
event: true
lib: false
main: false
melee: true
menu: false
mon: false
party: true
play: true
player: true
room: false
util: false
weap: false
]
Where each element represents a module of the program. Then the
testing-print function is defined as follows:
eprint: make object! [
adv: func [msg-raw [series!]][ if any [testing/adv testing/all][print
[ "^(tab)ADV: " reduce msg-raw ]]]
dun: func [msg-raw [series!]][ if any [testing/lib testing/all][print
[ "^(tab)DUNGEON: " reduce msg-raw ]]]
event: func [msg-raw [series!]][ if any [testing/event
testing/all][print [ "^(tab)EVENT: " reduce msg-raw ]]]
item: func [msg-raw [series!]][ if any [testing/weap
testing/all][print [ "^(tab)WEAP: " reduce msg-raw ]]]
lib: func [msg-raw [series!]][ if any [testing/lib testing/all][print
[ "^(tab)LIBRARY: " reduce msg-raw ]]]
main: func [msg-raw [series!]][ if any [testing/main
testing/all][print [ "^(tab)MAIN: " reduce msg-raw ]]]
melee: func [msg-raw [series!]][ if any [testing/melee
testing/all][print [ "^(tab)MELEE: " reduce msg-raw ]]]
menu: func [msg-raw [series!]][ if any [testing/menu
testing/all][print [ "^(tab)MENU: " reduce msg-raw ]]]
mon: func [msg-raw [series!]][ if any [testing/mon testing/all][print
[ "^(tab)MON: " reduce msg-raw ]]]
party: func [msg-raw [series!]][ if any [testing/party
testing/all][print [ "^(tab)PARTY: " reduce msg-raw ]]]
play: func [msg-raw [series!]][ if any [play-test testing/all][print
[ "^(tab)PLAY: " reduce msg-raw ]]]
player: func [msg-raw [series!]][ if any [testing/play
testing/all][print [ "^(tab)PLAYER: " reduce msg-raw ]]]
room: func [msg-raw [series!]][ if any [testing/room
testing/all][print [ "^(tab)ROOM: " reduce msg-raw ]]]
util: func [msg-raw [series!]][ if any [testing/util
testing/all][print [ "^(tab)UTIL: " reduce msg-raw ]]]
weap: func [msg-raw [series!]][ if any [testing/weap
testing/all][print [ "^(tab)WEAP: " reduce msg-raw ]]]
report: func ["Report the testing status"][
if play-test [print "* Game is being PLAY-TESTED."]
if testing/all [print "* Everything is being error-tested."]
foreach test-var (next first testing) [
if true = get in testing test-var [print ["*" test-var "is
being error-tested."]]
]
]
]
I can turn on ALL testing messages simply by setting:
testing/all: true
Or any individual module testing messages by, for example:
testing/main: true
I can then define a testing message by the following (for some reason I
don't need 'reform on the parameter block before passing it):
eprint/adv [ "Creating char:" form class-fields ", weapon:" wname ",
armor:" aname ", shield:" sname]
eprint/melee [ "Defender:" combatant/target/name " hp:" combatant/target/hp
]
eprint/report ; Displays all module being tested
- Michael Jelinek
[rishi--picostar--com] on 09/16/2000 08:57:16 PM
From: [rishi--picostar--com] on 09/16/2000 08:57 PM
Please respond to [list--rebol--com]
To: [list--rebol--com]
cc:
Subject: [REBOL] debugging rebol apps
Hi. Since rebol does not have a compiler, I find it a bit more difficult to
debug large rebApps.
Anyone have any debugging tips/strategies? Curious how others debug their
scripts...
Rishi
[3/6] from: jeff:rebol at: 18-Sep-2000 8:06
Incrementally. Each time I make a change that I think is
trivial, I still go make sure it works as expected. I break
out common code into functions, and then debug those functions
individually. Always add type specifiers to function arguments
to be sure you're being passed what is expected.
The thing that always seems to help for me is I'll try to make
each module do something very simple successfully before
elaborating. Like, for instance, if the goal of a function is
to generate some data and then display it (or have another
function display it) I make my first goal to successfully:
print mold data
When a script reaches the couple pages mark, I find it helps
to break out common parts, like utility functions, to go into
their own file. They can always be recombined later, but the
more scrolling you end up doing the more confusing it can become.
Nothing revolutionary in those approaches, but I find them
helpful in building larger apps.
-jeff
[4/6] from: jeff:rebol at: 18-Sep-2000 8:11
Howdy, Michael:
> Well, since you asked...
>
> I have a fairly large application, divided into several
> files (modules).
. . .
> eprint: make object! [
> adv: func [msg-raw [series!]][ if any [testing/adv
<<quoted lines omitted: 3>>
> testing/all][print
> [ "^(tab)DUNGEON: " reduce msg-raw ]]]
Wow, when do we get to see that? (-:
-Jeff
[5/6] from: jelinem1:nationwide at: 18-Sep-2000 13:18
Heheh, when it works. :D
- Michael Jelinek
[jeff--rebol--net] on 09/18/2000 10:11:18 AM
From: [jeff--rebol--net] on 09/18/2000 10:11 AM
Please respond to [list--rebol--com]
To: [list--rebol--com]
cc:
Subject: [REBOL] debugging rebol apps Re:(2)
Howdy, Michael:
> Well, since you asked...
>
> I have a fairly large application, divided into several
> files (modules).
. . .
> eprint: make object! [
> adv: func [msg-raw [series!]][ if any [testing/adv
<<quoted lines omitted: 3>>
> testing/all][print
> [ "^(tab)DUNGEON: " reduce msg-raw ]]]
Wow, when do we get to see that? (-:
-Jeff
[6/6] from: g:santilli:tiscalinet:it at: 18-Sep-2000 19:27
Hello [rishi--picostar--com]!
On 17-Set-00, you wrote:
r> Hi. Since rebol does not have a compiler, I find it a bit more
r> difficult to debug large rebApps. Anyone have any debugging
r> tips/strategies? Curious how others debug their scripts...
Actually, interpreted languages are usually much easier to debug
than compiled ones.
WRT REBOL, you can add PROBEs to you code to see what happens;
this is the method I prefer, but you need to know where to put
PROBEs. Sometime you might want to use TRACE, as in:
trace on
; piece of code to debug
trace off
but note that this produces a lot of output.
A good advice, that you surely know, is to subdivide you problem
into subproblems, and subdivide your code into functions. This way
you can debug every function individually at the console, before
testing the whole program.
HTH,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted