REPOST: Re: Two languages, too similar, competing in the same space.
roy at panix.com
Sat Dec 29 19:40:16 CET 2001
gerson.kurz at t-online.de (Gerson Kurz) wrote:
> Call me oldfashioned, but I don't like exception handling - I like
> if-then-else and error checking style.
I am certainly old fashioned. I thought FORTRAN was a great step up from
writing in assembler. I've been doing python for about 4 years now, and
I'm only just starting to really warm up to the idea of using exceptions on
a regular basis, but I've finally gotten the hang of it (by which I mean
not just learning the syntax, but getting to the point where it just seems
I've been writing lots of parsers lately, for every sort of data file we
use. Each new parser is a subclass of a genericFileParser class I wrote
(which takes care of low level stuff like reading the file, allowing lines
to be pushed back onto the input stream to be reread later, keeping track
of line numbers, and formatting error messages). Some of the parsers are
pretty complex, employing state machines.
Anyway, genericFileParser includes a parseError() method. A specific file
parser subclass can just do:
If len(blurfl) != 42:
self.parseError ('bogus length for blurfl')
and you end raising genericFileParser.ParseError with an argument of
something like 'parse error in file foo.baz, line 47: bogus length for
blurfl'). The really nice thing is it could have been generated deep in a
function call chain, and I don't have to worry about propigating the error
indication back up the chain.
Even nicer, when I'm prototyping a new application, I don't have to worry
about error checking at all; I just call my parser and assume everything
works as it's supposed to. With return-status type error checking, if I
got lazy and didn't check for errors, my program would just continue
merrily on its way producing garbage, or mysteriously crashing at some
other remote point in the code. With exceptions, if I fail to catch the
exception, I blow out of the interpreter with a stack track, so I catch the
error right away. Often times, all I'm going to do when I catch the error
is exit cleanly with a nicely formatting message, but I can add that code
later, at my convenience.
========= WAS CANCELLED BY =======:
From: Roy Smith <roy at panix.com>
Subject: cmsg cancel <roy-AD2FE2.13401629122001 at news1.panix.com>
Control: cancel <roy-AD2FE2.13401629122001 at news1.panix.com>
Date: Mon, 31 Dec 2001 02:23:55 GMT
Organization: A poorly-installed InterNetNews site
Message-ID: <cancel.roy-AD2FE2.13401629122001 at news1.panix.com>
X-Trace: news2.kornet.net 1009774625 27193 188.8.131.52 (31 Dec 2001 04:57:05 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 04:57:05 +0000 (UTC)
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)
This message was cancelled from within Mozilla.
More information about the Python-list