Go Programming talk [OT]
"Jérôme M. Berger"
jeberger at free.fr
Tue Jun 8 11:33:19 PDT 2010
Leandro Lucarella wrote:
> Ali Çehreli, el 7 de junio a las 14:41 me escribiste:
>> Leandro Lucarella wrote:
>>
>>> Go doesn't have exceptions, so scope(failure/success) makes no sense.
>>> You can argue about if not having exceptions is good or bad (I don't
>>> have a strong opinion about it, sometimes I feel exceptions are nice,
>>> sometimes I think they are evil), though.
>> Just to compare the two styles...
>>
>> Without exceptions, every step of the code must be checked explicitly:
>>
>> // C code:
>> int foo()
>> {
>> int err = 0;
>>
>> // allocate resources
>>
>> err = bar();
>> if (err) goto finally;
>>
>> err = zar();
>> if (err) goto finally;
>>
>> err = car();
>> if (err) goto finally;
>>
>> finally:
>> // do cleanup
>>
>> return err;
>> }
>>
>> (Ordinarily, the if(err) checks are hidden inside macros like
>> check_error, check_error_null, etc.)
>>
>> With exceptions, the actual code emerges:
>>
>> // C++ or D code
>> void foo()
>> {
>> // allocate resources
>>
>> bar();
>> zar();
>> car();
>> }
>
> You are right, but when I see the former code, I know exactly was it
> going on, and when I see the later code I don't have a clue how errors
> are handled, or if they are handled at all. And try adding the try/catch
> statements, the code is even more verbose than the code without
> exceptions.
>
> Is a trade-off. When you don't handle the errors, exceptions might be
> a win, but when you do handle them, I'm not so sure. And again, I'm not
> saying I particularly like one more than the other, I don't have a
> strong opinion =)
>
Of course, the problem is that you rarely see the former code. Most
of the time, people just write the second one with or without
exceptions and don't bother about error checking if there are no
exceptions. You are a lot more likely to get them to handle errors
properly with exceptions than without (particularly with D's scope
statements).
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100608/a6228a31/attachment.pgp>
More information about the Digitalmars-d
mailing list