On 12/24/10 4:24 AM, Steven D'Aprano wrote:
On Thu, 23 Dec 2010 22:38:05 -0800, Carl Banks wrote:

OTOH, going the extra mile to hide useful information from a user is
asinine. As a user, I will decide for myself how I want to use
implementation-defined information, and I don't want the implementor to
decide this for me. It's bad enough if an implementor fails to provide
information out of laziness, but when they deliberately do extra work to
hide information, that's self-importance and arrogance.

But that of course is nonsense, because as the user you don't decide
anything of the sort. The developer responsible for writing the function
decides what information he provides you, starting with whether you get
an exception at all, where it comes from, the type of exception, and the
error message (if any).

Carl isn't arguing that the user is or should be responsible for this sort of thing. He is arguing that developers should be responsible for doing this in such a way that is beneficial for the developer/user down the road.

Once this information has been passed on to you,
you're free to do anything you like with it, but you never get to choose
what information you get -- I'm not suggesting any change there. All I'm
suggesting is that there should be a way of reducing the boilerplate
needed for this idiom:

def _validate_arg(x):
     if x == 'bad input': return False
     return True

def f(arg):
     if not _validate_arg(arg):
         raise ValueError
     process(arg)

to something more natural that doesn't needlessly expose implementation
details that are completely irrelevant to the caller.

Except that the *caller* never gets the traceback (unless if it deliberately inspects the stack for some metaprogramming reason). It gets the exception, and that is the same no matter what you do. The developer/user gets the traceback, and those implementation details *are* often important to them.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to