Go Programming talk [OT]

Ali Çehreli acehreli at yahoo.com
Mon Jun 7 14:41:13 PDT 2010


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();
}

Ali


More information about the Digitalmars-d mailing list