Re: Calling Func/Proc

new topic     » goto parent     » topic index » view thread      » older message » newer message

c.k.lester wrote:
> Robert Craig wrote:
> > I don't think we want to start 
> > adding features that are not supported by the Translator, 
> > unless there is a very good reason for it.
> 
> I agree.
> 
> > Is it that inconvenient to just add a parameter to the routine,
> > or set a global variable with the name of the calling routine?
> 
> It is inconvenient and would violate the DRY principle.
> (<a
> href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">http://en.wikipedia.org/wiki/Don't_repeat_yourself</a>)
> 
> I would have to add parameters to hundreds of routines.
> 
> > Can we see some examples of where this would be useful. C.K.?
> 
> I have a procedure called err() that gets passed an error message. err() is
> called from hundreds of functions and procedures all spread throughout my
> code. I usually call it like in this small example:
> 
> function rev_string(sequence x)
>    if length(x) = 0 then
>       err("rev_string(): Must be at least 1 character in length."
>    else
>       if length(x) > 17 then
>          err("rev_string(): String too long."
>       else
>          x = reverse(x)
>       end if
>    end if
>    return x
> end function
> 
> A "fixed" version would look like this:
> 
> function rev_string(sequence x)
>    if length(x) = 0 then
>       err("Must be at least 1 character in length."
>    else
>       if length(x) > 17 then
>          err("String too long."
>       else
>          x = reverse(x)
>       end if
>    end if
>    return x
> end function
> 
> This is a very short example. When dealing with a much larger func/proc,
> there may be many more calls to err. Sometimes I change the name of a
> func/proc. When that happens, I also have to adjust all the calls to err.
> 
> You suggest something like this:
> 
> function my_super_function()
>    CURR_ROUTINE = "my_super_function"
>    --or
>    set_routine_name( "my_super_function" )
>    ...
> end function
> 
> but that violates DRY and, again, would have to be done for hundreds of
> func/proc in my code. It is unnecessary overhead to something that should
> be quite simple to resolve.
> 
> What about if I want to trace the call back a few func/procs? It makes
> manual tracking even more complicated and time consuming.
> 
> Say that a calls b calls c which calls my_super_function... To track the
> progress, you need something like:
> 
> function my_super_function()
>    add_routine_name( "my_super_function" )
>    -- do your stuff
>    remove_routine_name( "my_super_function" )
> end function
> 
> I'm open to suggestions, but the fact is, the most efficient way to
> do this tracking of func/proc hierarchy is to let the interpreter/translated
> program handle it.
> 
> The reason I need it is primarily for error handling/messaging and debugging.

Have you considered using crash_routine()?
http://www.rapideuphoria.com/lib_c_d.htm#crash_routine

After displaying your message, you could force an error, 
say with ?1/0, and then display part of the ex.err file 
(e.g. traceback) for the user, and maybe even email the 
full ex.err to yourself, before dying. Most of my CGI programs
email the ex.err to me when they are about to die. 
It works fine. Sometimes I add an extra message in the email
along with the ex.err.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu