|
Re: Business Exceptions v Core Code
On Mon, 26 Apr 2004 03:58:42 -0700, Ian Tebbutt wrote:
[snip]
> Result is that >75% of code is built to handle business exceptions,
> but >75% of design effort goes into the core. And that is a key reason
> why so much of our software fails - the code for exceptional
> circumstances is not as well designed, and the exceptions themselves
> are less understood and have greater variability and complexity.
Bouncer Pattern may help you, separate exception bailout from the core
code, hopefully making the core more readable.
Have a look at the methods prefixed with 'check_'..
def check_not_endofinput(context)
return if context.input.has_next?
context.raise_mismatch("(Inside) end of input")
end
def is_member_of_set?(symbol)
@set.each do |i|
return true if i.kind_of?(Range) and i.include?(symbol)
return true if i == symbol
end
false
end
def check_member_of_set(context)
symbol = context.current
return if is_member_of_set?(symbol)
context.raise_mismatch(
"(Inside) symbol #{symbol.inspect} is not in set #{@set.inspect}")
end
Now comes the core code.. as you can see all exception
throwing is easy to overview.
def match(context)
check_not_endofinput(context)
check_member_of_set(context)
context.input_next { @succ.match(context) }
end
Were this what you were looking fore ?
--
Simon Strandgaard
|