From: Robert Klemme Date: 2004-02-26T18:39:49+09:00 Subject: Re: [ot] proposal: debug keyword "Charles Comstock" schrieb im Newsbeitrag news:c1jbfq$eiv$1@newsreader.wustl.edu... > Simon Strandgaard wrote: > > > On Wed, 25 Feb 2004 15:38:53 +0100, Robert Klemme wrote: > > > >>"Simon Strandgaard" schrieb im Newsbeitrag > >> > >>>Any ideas for a good name? > >>> > >>>debug replacement puts -> #debug_puts, #dputs > >>>debug replacement p -> #debug_p, #dp > >> > >>Hm... I'd go for "d_puts" which is immediately distinguished from "puts" > >>but is not so much typing overhead as the more verbose "debug_puts". > >> > >> > >>>maybe just turn the 'p' in 'puts' upsidedown, so it becomes a 'd' => > >> > >>duts? > >> > >>http://www.best-lyrics-zone.net/Upside_Down_Lyrics.html > >>:-) > >> > > > > > > BTW: I had to change my taste of music so it reflect the language I am using > > > > diamonds are forever > > lucy in the sky with diamonds > > diamonds are a girls best friend > > > > -- > > Simon Strandgaard > > It would be nice if we had macros for the debug stuff, so the code would > never even be seen when you didn't do debug code. For instance if > instead for debug output you had a debug block, which was evaled and > added to the code on the first pass, so it would execute all further > passes. This would only occur if $debug was set, otherwise the code > would never be evaled, and we wouldn't even test to see if the verbose > flag was set, and thus it would never actually get executed. I suppose > this could also be simulated if we had constant propagation in the > interpreter, so that a constant if expression would be eliminated. I don't mandate a preprocessor since Ruby is flexible enough and we all know what Bjarne said about one of his biggest mistakes with C++... :-) IMHO this is as efficient as it can get without a macro preprocessor. The overhead is a single method call and a boolean test for non debug mode: module Kernel def debug yield if $DEBUG end end Then you can do: def foo debug { # complex calculations might be here } # normal operation end > Another comment though, I really hate having only the ability to turn > debug output off globally. It's much nicer to be able to turn it all on > or off, but also be able to turn it on per the scope you are in. That's what Simon's suggestion was all about. :-) robert