Exception as the primary error handling mechanism?

r0g aioe.org at technicalbloke.com
Tue Jan 5 11:31:03 CET 2010


Paul Rudin wrote:
> r0g <aioe.org at technicalbloke.com> writes:
> 
>> Steven D'Aprano wrote:
>>> On Tue, 05 Jan 2010 02:31:34 +0000, r0g wrote:
>>>
>>>> A pattern I have used a few times is that of returning an explicit
>>>> success/failure code alongside whatever the function normally returns.
>>> That doesn't work for languages that can only return a single result, 
>>> e.g. C or Pascal. You can fake it by creating a struct that contains a 
>>> flag and the result you want, but that means doubling the number of data 
>>> types you deal with.
>>
>> No, but that's why I try not to use languages where you can only return
>> a single result, I always found that an arbitrary and annoying
>> constraint to have. I leads to ugly practices like "magic" return values
>>  in C or explicitly packing things into hashtables like PHP, yuk!
> 
> Doesn't python just return a single result? (I know it can be a tuple and
> assignment statements will unpack a tuple for you.)


Yes, it returns a tuple if you return more than one value, it just has a
 lovely syntax for it. In static languages you'd need to manually create
an new array or struct, pack your return vars into it and unpack them on
the other side. That's something I'd be happy never to see again, sadly
I have to write in PHP sometimes :(

Roger.



More information about the Python-list mailing list