Go Programming talk [OT]

Leandro Lucarella llucax at gmail.com
Mon Jun 7 18:35:56 PDT 2010


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 =)

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Qué sabía Galileo de astronomía, Mendieta! Lo que pasa es que en este
país habla cualquiera.
	-- Inodoro Pereyra


More information about the Digitalmars-d mailing list