Comparison with False - something I don't understand

Tim Harig usernet at ilthio.net
Thu Dec 2 10:25:55 EST 2010


On 2010-12-02, Harishankar <v.harishankar at gmail.com> wrote:
> There are some reasons why I hate exceptions but that is a different 
> topic. However, in short I can say that personally:
>
> 1. I hate try blocks which add complexity to the code when none is 
> needed. Try blocks make code much more unreadable in my view and I use it 
> only for the built-in exceptions when absolutely needed.

Actually, exceptions remove a ton of complexity and almost universally
remove a ton of redundant error checking code.  Second, they aleviate a
ton of design complexity about designing a clean and unified method of
error handling throughout the program.  Using exceptions, the only real
questions are where to handle various errors.  It is a godsend for having
to clean up intermediary results when an error occurs as part of a complex
set of dependant sequential operations.

> 2. I prefer the less irksome True or False to do error checking. 
> Exceptions seem too heavyweight for simple problems.

Error handling in C huge source of bugs.  First, error handling code is
scattered throughout the codebase and second it is hard to test the error
handling code for a number of failures.  Being able to raise exceptions
within your test code makes it much easier to write tests capable of
detecting error handling bugs.

> 3. Philosophically I think exception handling is the wrong approach to 
> error management. I have never grown up programming with exceptions in C 
> and I couldn't pick up the habit with python either. Did I mention that I 
> detest try blocks? try blocks seem ugly and destroy code clarity at least 
> in my view. And enclosing single statements under separate try blocks 
> seem to add a lot of clutter. 

Perhaps you should take a look at how Erlang appoaches exception handling.
Being message passing and concurrency oriented, Erlang encourages ignoring
error conditions within worker processes.  Errors instead cause the worker
processes to be killed and a supervisory process is notified, by message,
so that it can handle the error and respawn the worker process.  Since it
doesn't use try/exept blocks, maybe that will be more to your liking.



More information about the Python-list mailing list