Re: Assertion vs Exception Handling
On Mar 19, 8:16 pm, Ian Collins <ian-n...@hotmail.com> wrote:
On 03/20/10 08:45 AM, James Kanze wrote:
On Mar 18, 8:09 pm, Ian Collins<ian-n...@hotmail.com> wrote:
On 03/19/10 07:21 AM, James Kanze wrote:
On 18 Mar, 11:20, "Leigh Johnston"<le...@i42.co.uk> wrote:
"Yannick Tremblay"<ytrem...@nyx.nyx.net> wrote in message
[...]
The motivation for SESE is to facilitate proving that the
code works as intended. You leave via an exception when you
know that it can't work as intended. (For some appropriate
definition of "intended", of course.)
I agree SESE can make code analysis easier, but Yannick's
example in his reply is a strong counter example. I also
prefer an immediate return if a precondition test fails.
Yes. It's a general rule, not an absolute. I violate it myself
in some cases[1]. In practice, I feel that keeping the function
simple and concise is more important. Not that one precludes
the other, but in my experience, if analysing the function isn't
trivial, it's more often because the function is too complicated
to begin with---SESE would make the analysis simpler, but
breaking the function down into smaller functions would make it
even simpler.
[1] In one case, I don't think it's even possible to follow it.
I have a function which consists of nothing but a switch, each
of which cases ends in a return. The return type doesn't have a
default constructor (and the switch covers all of the cases).
--
James Kanze