comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: OT: A bit  of Sudoku
Date: Thu, 5 Jun 2014 16:39:47 -0700 (PDT)
Date: 2014-06-05T16:39:47-07:00	[thread overview]
Message-ID: <c0760c4e-8809-4c04-b454-3cd5bdc98538@googlegroups.com> (raw)
In-Reply-To: <wccbnu73q88.fsf@shell01.TheWorld.com>

On Thursday, June 5, 2014 4:12:55 PM UTC-7, Robert A Duff wrote:

> In any case, if you need to jump out of many layers of (recursive?)
> calls, an exception might well be the best way.  Checking error
> codes at each level might be verbose and error prone.

I don't like it.  But if you do something like this, I'd suggest that this use be limited to an exception that you declare inside a subprogram, so that you raise and handle it only inside that subprogram or nested subprograms.  Otherwise, someone could look at a subprogram that is called in between, and never guess that the subprogram might not complete normally (A calls B, B calls C, C raises an exception that gets passed over B's head back to A; a programmer trying to read B might not suspect that B may not complete in a non-error situation.)  In other words, keep such usages as localized as possible.

Another thing to keep in mind is that exceptions cause overhead.  I've seen implementations that have to do some stuff any time a subprogram or a block with an exception handler is entered.  I've seen other implementations that, in order to eliminate this overhead in "normal" (non-exception) cases, perform table lookups on each address in the stack until it finds a handler; this is a relatively expensive operation that those implementations have decided is justified because exceptions aren't supposed to happen in "normal" cases.  Whether this overhead is less than the expense of going through a number of returns, I don't know--I'm sure it depends on various factors.  But efficiency should not be a reason to use exceptions instead of straight returns, because it may well make things slower.

                                     -- Adam


  reply	other threads:[~2014-06-05 23:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:49 OT: A bit of Sudoku Mike H
2014-06-05 18:30 ` Adam Beneschan
2014-06-05 19:00   ` J-P. Rosen
2014-06-05 19:18     ` Jeffrey Carter
2014-06-05 19:43       ` J-P. Rosen
2014-06-05 20:05     ` Mike H
2014-06-05 23:12     ` Robert A Duff
2014-06-05 23:39       ` Adam Beneschan [this message]
2014-06-06  7:51         ` Dmitry A. Kazakov
2014-06-06  9:21           ` Georg Bauhaus
2014-06-06 13:38             ` Dmitry A. Kazakov
2014-06-06 15:47           ` Adam Beneschan
2014-06-06 17:09             ` Dmitry A. Kazakov
2014-06-07  6:03             ` J-P. Rosen
2014-06-06 14:13         ` Brad Moore
2014-06-13  0:21     ` Shark8
2014-06-13  6:30       ` J-P. Rosen
2014-06-13 10:10       ` Mike H
2014-06-13 12:37         ` Dmitry A. Kazakov
2014-06-13 15:47         ` Shark8
2014-06-05 20:03   ` Mike H
2014-06-05 20:40     ` Adam Beneschan
2014-06-06  9:10       ` Stefan.Lucks
2014-06-06 10:59         ` Mike H
2014-06-06 16:06         ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox