1. Radical New Debug Tool

Proposal for debug tool:

When a . begins a line, it is considered debug code.

If the user puts 'with debug' at the top, code that begins with . is run.
When no declaration is made or 'without debug' is explicitly set, any line
of code that begins with a . is treated as a comment.

For example:

with debug

for t=1 to length(sql[2]) do
    .position(1,1)
    .puts(1,"Field 'NAME' is " & sql[2][t][3])
    run_query( "update people set name='" & sql[2][t][3] & "' where id = 3" )
end for

The two lines, position() and puts(), would be run in this case. Without
debug turned on, they would be treated as comments.

This avoids having to utilize this slower implementation:

for t=1 to length(sql[2]) do
    if DEBUG then
       position(1,1)
       puts(1,"Field 'NAME' is " & sql[2][t][3])
    end if
    run_query( "update people set name='" & sql[2][t][3] & "' where id = 3" )
end for

Of course, it doesn't have to be a '.'. But I would prefer a one-character-
in-length indicator that can be typed without the shift key.

new topic     » topic index » view message » categorize

2. Re: Radical New Debug Tool

c.k.lester wrote:
> 
> Proposal for debug tool:
> 
> When a . begins a line, it is considered debug code.
> 
> If the user puts 'with debug' at the top, code that begins with . is run.
> When no declaration is made or 'without debug' is explicitly set, any line
> of code that begins with a . is treated as a comment.
> 
> For example:
> 
> with debug
> 
> for t=1 to length(sql[2]) do
>     .position(1,1)
>     .puts(1,"Field 'NAME' is " & sql[2][t][3])
>     run_query( "update people set name='" & sql[2][t][3] & "' where id = 3"
> )
> end for
> 
> The two lines, position() and puts(), would be run in this case. Without
> debug turned on, they would be treated as comments.
> 
> This avoids having to utilize this slower implementation:
> 
> for t=1 to length(sql[2]) do
>     if DEBUG then
>        position(1,1)
>        puts(1,"Field 'NAME' is " & sql[2][t][3])
>     end if
>     run_query( "update people set name='" & sql[2][t][3] & "' where id = 3"
> )
> end for
> 
> Of course, it doesn't have to be a '.'. But I would prefer a one-character-
> in-length indicator that can be typed without the shift key.

Have you looked at Derek Parnell's assert() code?

http://www.openeuphoria.org/cgi-bin/esearch.exu?fromMonth=6&fromYear=1&toMonth=8&toYear=C&postedBy=Derek+Parnell&keywords=assert%28


--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Radical New Debug Tool

Jason Gade wrote:
> c.k.lester wrote:
> > Proposal for debug tool:
> > When a . begins a line, it is considered debug code.
> Have you looked at Derek Parnell's assert() code?

With my proposal, Derek's code would be faster when not debugging. It would
avoid all the "if vUnitTesting..." tests when debugging is turned off.

With my proposed solution:

-- math.e
constant vUnitTesting = find("-unittest", command_line())
include assert.e as assert

if vUnitTesting then
    debug 1 -- instead of a 'with debug' use 'debug X' where x is true or
            -- false (default setting)
end if

---------------------------------------------------------
global function abs(object pData)
---------------------------------------------------------
    object lTemp

    if atom(pData) then
        if pData >= 0 then
            return pData
        end if
        return -pData
    end if

    for i = 1 to length(pData) do
        lTemp = pData[i]
        if atom(lTemp) then
            if lTemp < 0 then
                pData[i] = -lTemp
            end if
        else
            pData[i] = abs(lTemp)
        end if
    end for

    return pData
end function

    .assert:assert(abs(0), 0, "abs0")
    .assert:assert(abs(3), 3, "abs1")
    .assert:assert(abs(-3),  3, "abs2")
    .assert:assert(abs(3.21),  3.21, "abs3")
    .assert:assert(abs(-3.21),  3.21, "abs4")
    .assert:assert(abs({1,-2,3,-4}),  {1,2,3,4}, "abs5")
.assert:assert(abs({1,-2,{3.1,-3.2,-3.3},-4}),  {1,2,{3.1,3.2,3.3},4},
    "abs6")


Those last lines are skipped over as comments without the need for an if
statement. Of course, the interpreter now has to check for {"--","."} if
debug is turned on instead of just "--".

Just a thought. Looks like it could work.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Radical New Debug Tool

c.k.lester wrote:
> 
> Proposal for debug tool:
> 
> When a . begins a line, it is considered debug code.
> 
> If the user puts 'with debug' at the top, code that begins with . is run.
> When no declaration is made or 'without debug' is explicitly set, any line
> of code that begins with a . is treated as a comment.
> ...SNIP...
> Of course, it doesn't have to be a '.'. But I would prefer a one-character-
> in-length indicator that can be typed without the shift key.

I can see a lot of benefit from this.  It doesn't break existing code and
it could improve runtime performance when not debugging.  I vote yes.

For simple projects, I would likely use this method; but for more complicated
or distributed projects, I would probably use the more classic "if DEBUG 
then" method.  Here's why: any "with" statement cannot (and should not) be
defined within an "if".  I say "should not" because Euphoria does not 
presently support compiler directives (e.g., conditional includes).  That's
a whole other debate, but I don't think it should be introduced in this 
context only.  Also, I generally declare my DEBUG symbol to be a variable
atom rather than a constant so it can be set from the command line or via
a runtime API (or options box).  Your proposal wouldn't prevent me from 
still doing that, but it would give me another option when all I need is a 
simple on/off that the end user can't touch.

I vote YES.

Michael J. Sabal

new topic     » goto parent     » topic index » view message » categorize

5. Re: Radical New Debug Tool

Michael J. Sabal wrote:
> c.k.lester wrote:
> > When a . begins a line, it is considered debug code.
> For simple projects, I would likely use this method; but for more complicated
> or distributed projects, I would probably use the more classic "if DEBUG 
> then" method.  Here's why: any "with" statement cannot (and should not) be
> defined within an "if".  I say "should not" because Euphoria does not 
> presently support compiler directives (e.g., conditional includes).

What about my mod of Derek's code?

constant vUnitTesting = find("-unittest", command_line())

if vUnitTesting then
    debug 1 -- instead of a 'with debug' use 'debug X' where x is true or
            -- false (default setting)
end if


Would that work better?  I guess you could even mix types at that point,
though I can't imagine a scenario where that would be beneficial/useful.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Radical New Debug Tool

c.k.lester wrote:
> 
> }}}
<eucode>constant vUnitTesting = find("-unittest", command_line())
> 
> if vUnitTesting then
>     debug 1 -- instead of a 'with debug' use 'debug X' where x is true or
>             -- false (default setting)
> end if</eucode>
{{{

> 
> Would that work better?  I guess you could even mix types at that point,
> though I can't imagine a scenario where that would be beneficial/useful.

If we did it the same way as trace, I think that would work fine.
with debug  -- at the top of the program, compiler parses dotted code as
-- conditionally executed statement blocks.
debug(0) -- do not execute dotted code
debug(1) -- execute code with a single dot
debug(2) -- execute code with one or two dots
debug(3) -- execute code with one, two, or three dots
etc.

This would already be familiar from the way trace works, and if "with trace"
is omitted from the top, all dotted code would be compiled as comments and
debug() calls would end up doing nothing (probably also optimized out of
the resultant IL).

It may be a little more complicated than the original; but I think it would 
be a valuable enhancement.  Perhaps the with debug and dot parsing could be
done in one release (with debug(1) as the default), and debug() calls in 
another.  I know you recommended the calls without parentheses, but I can
easily see myself getting tripped up by that for being so different from
anything else Euphoria does.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu