Go Programming talk [OT]

Bane branimir.milosavljevic at gmail.com
Tue Jun 8 11:42:46 PDT 2010


Jérôme M. Berger Wrote:

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

Being lazy as I am, exceptions are faster and easier to use than manual error checking. There will always be some unchecked return value, with exceptions it can't happen. In a way same as GC vs manual memory handling.

Each thread of program I make I always enclose in try catch, so everything is cought.
> 



More information about the Digitalmars-d mailing list