From: Gavin Sinclair Date: 2004-11-14T01:20:49+09:00 Subject: Re: assert On Sunday, November 14, 2004, 2:48:24 AM, Florian wrote: > Gavin Sinclair wrote: >>>>>I have thought about changing the name to "assume" so it can be included >>>>>in dev-utils, but I'm not sure if that name is better. >>>I think that would be way too much magic. I'd expect the method to just >>>take a block. >> >> Why a block? The breakpoint code uses Binding.of_caller anyway, so a >> block is not needed for evaluation. I don't see any other reason, >> technical or stylistic, why a block should be preferred. > Using strings for code is a bit ugly. We have blocks in Ruby, why not > use them? Using a String also causes a bit of escaping trouble (I know > this can be worked around via the %{} or <<-END syntax, but I still > think blocks are clearer than that.) Agreed, but you can print strings. You can't print blocks. See below. >> I suppose we might as well dispose of the symbolic argument and just >> do this: >> >> breakpoint_unless 'x + y == 10' > Why don't just use "breakpoint unless x + y == 10" then? I think it > makes sense to use something more concise here. That option is still available. breakpoint_unless 'x + y == 10' has the added benefit that the breakpoint can be identified by the condition that triggered it. E.g. you run the program and see on the console: Breakpoint because 'x + y == 10' is false. irb> Is that a convincing benefit? >> Can you expand on the "too much magic"? > I don't know -- the syntax just seemed so very unnatural. Like something > you wouldn't meet anywhere in the standard library... Debugging code often stands out in this unfortunate way, though. It's lower level than normal code. Now let me ask you: since you proposed assume { x + y == 10 } what does that provide over breakpoint unless x + y == 10 ? Gavin