First release of Shed Skin, a Python-to-C++ compiler.

Mark Dufour mark.dufour at gmail.com
Mon Sep 12 19:01:56 CEST 2005


On 9/12/05, Brian Quinlan <brian at sweetapp.com> wrote:
> Mark Dufour wrote:
> > The latter is certainly my goal. I just haven't looked into supporting
> > exceptions yet, because I personally never use them. I feel they
> > should only occur in very bad situations, or they become goto-like
> > constructs that intuitively feel very ugly. In the 5500 lines of the
> > compiler itself, I have not needed to use a single exception. For
> > example, I prefer to check whether a file exists myself, rather than
> > executing code that can suddenly jump somewhere else. There's probably
> > some use for exceptions, but I don't (want to?) see it.
> 
> I don't understand your example here. When you check that a file exists,
> you feel safe that openning it will succeed? What if:
> 
> o you don't have permission to open the file
> o the file is deleted in the time between you checking for it's
>    existance and opening it (possible race condition)
> o the system doesn't have sufficient resources to open the file
>    e.g. too many open file handles
> o the file is already open with exclusive read/write permission

You're right, I don't feel safe about that. It's a bad example. I just
prefer error codes, because the code usually becomes cleaner (at least
to me). I would really like it if I could do something like this:

f = file(name) 
if not f:
    print 'error opening file %s: %s', name, str(f.error)
    sys.exit()

Error codes may be more work in some cases, but I really like the
(subjectively) cleaner code.  Again, exceptions are probably useful in
some programs, but I wouldn't know.. :)


thanks!
mark.



More information about the Python-list mailing list