Tomek CEDRO wrote:
> > Please just use goto to handle errors.
> 
> "goto hell" ;-)
> 
> God function looks like:
> 
> input o---[function]---o output

Agree.


> no other :-) no gotos :-) no globals :-) nice program flow :-) clean
> and self commentary code :-) good vibration :-) :-)

Indeed what you get with good use of goto. The rule is basically to
only goto in the forward direction within a function. It's very
simple, and it can make code *tremendously* more readable.

int thing(params) {
  if (error)
    goto handle_errors;

  if (other_error)
    goto handle_errors;

  if (third_error)
    goto handle_errors;

  /* all conditions have been checked, it's safe to do the thing */

  for (num = 0; num < times; num++)
    do_thing();

  return 0;

handle_errors:
  clean_up();
  return 1;
}


//Peter
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to