From: Eric Mahurin Date: 2005-09-11T02:32:39+09:00 Subject: Re: quick print type debugging --- Florian Gro� wrote: > Eric Mahurin wrote: > > > I just took a peek at your code. This could be quite slow > > because it uses Binding#of_caller (searches stack, uses > > continuations) and eval. I don't particularly like the > idea of > > putting code in a string (editors treat it like a string > rather > > than code). Oh, and having this debug/trace method return > the > > expression value would be very useful. > > Why do you think that this is too slow? It's something that > only happens > when debugging. Putting the string into a block doesn't help > at all > because strings are generated at parse-time so you avoid no > overhead at all. > > True, getting the caller's binding isn't exactly fast, but it > only > happens when debugging. I think you are overrating this as > you can make > trace() a noop when $DEBUG is false. (Just like I do with > assert { } in > ruby-breakpoint.) > > I'm pretty sure that Proc#source is way slower than the > Binding.of_caller solution, by the way. My proposal was that this expression passed to this trace/debug method always be evaluated (and returned) so that you could transparently trace any sub-expression in a larger expression. I think this would make it an extremely quick way to add traces anywhere in a piece of code (except LHS of assigns - but you could trace the whole assign). I was thinking you might leave some of this in your code indefinitely and control by a debug level, but some you may put in temporarily. I wouldn't mind if getting the file, line, and source of the expression was slow because that would only be done during debugging - but not the expression evaluation. Maybe a way to get around the slowness of Binding#of_caller would be to modify the string expression after the first call and give it a "call" method (similar to what I proposed for the expression in a string in a block). That way you'd only need Binding#of_caller and eval once per string expression. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com