Re: What do you think about the code?



goose wrote:
Ian Collins wrote:

Frederick Gotham wrote:


<snipped>

In my own humble opinion, I think it's childish to outright ban something
when it comes to computer programming -- I feel it gives an air of
inconfidence in one's competence.


Well that's team democracy at work. We preferred well structured code
that was easy to refactor. Try extracting your inner loop to a function.

Do you program in a language other than C? Do you use exceptions
in those languages? Exceptions are just another form of gotos,
only its "goto that location and tell the code there that this
happened" and not just "goto the error location, it will
unconditionally execute code to handle errors". No one ever seemed
to have trouble refactoring code which generated excetpions.

I do, several. As you say in the next paragraph, exceptions provide a
structured way of passing control. They are /not/ another form of goto,
they do a lot more than simply jumping to another location. There are
plenty of techniques for writing exception safe code. I can't think of
any for writing goto safe code!

If exceptions simply did a longjump, people wouldn't use them.

Ban away all you want; exceptions got popular *because*
developers wanted a structured way to handle errors. Handling
errors is not part of the algorithm logic; I see a benefit in
moving the code that checks for and handles specific errors
outside the block that contains the logic. Others see this benefit
as well, hence the popularity of exceptions.

I'm one of them.

Don't confuse exceptions with gotos, the mechanisms are completely
different. A goto jumps to fixed location, if there are locks held, or
memory to be freed, tough. Exceptions unwind the callstack, allowing
objects created on the stack to be destroyed and any resources they have
claimed to be freed.

Did you ban setjmp/longjmp too?

Yes. Remember this wasn't me, it was my team. I didn't tell them not
to use goto, they decided.

goose,
not being rhetorical - I'd really like to know.



--
Ian Collins.
.



Relevant Pages

  • Re: What do you think about the code?
    ... Do you program in a language other than C? ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ... Within a fixed scope, but you still identify the error handler (the ...
    (comp.lang.c)
  • Re: What do you think about the code?
    ... I think it's childish to outright ban something ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ...
    (comp.lang.c)
  • Re: Java needs "goto" (was Re: hi)
    ... Assemblers need "goto" but no decent HLL does. ... I don't use this construction in C either and, again, don't need it. ... Yes - but that's a result of classes that throw exceptions when their methods would be better off returning control values. ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)
  • Re: What do you think about the code?
    ... Do you program in a language other than C? ... Exceptions are just another form of gotos, ... only its "goto that location and tell the code there that this ... Anything allocated on the stack will get freed when longjmp gets ...
    (comp.lang.c)
  • Re: What do you think about the code?
    ... Within a fixed scope, but you still identify the error handler (the ... If exceptions are available, I'd rather throw ... I'd chuck in a goto rather than have the logic code do ... longjmp cannot call destructors automatically like ...
    (comp.lang.c)